Shubham Ankit

Shubham Ankit

1563259974

A beginner’s guide to Docker — how to create your first Docker application

After a short introduction on what Docker is and why to use it, you will be able to create your first application with Docker.

What is Docker?

Docker is a free software developed by Docker Inc. It was presented to the general public on March 13, 2013 and has become since that day a must in the world of IT development.

It allows users to create independent and isolated environments to launch and deploy its applications. These environments are then called containers.

This will let the developer run a container on any machine.

As you can see, with Docker, there are no more dependency or compilation problems. All you have to do is launch your container and your application will launch immediately.

But, is Docker a virtual machine?

Here is one of the most asked question about Docker. The answer is: actually, not quite.

It may look like a virtual machine at first but the functionality is not the same.

Unlike Docker, a virtual machine will include a complete operating system. It will be independent and act like a computer.

Docker will only share the resources of the host machine in order to run its environments.

Why use Docker as a developer?

This tool can really change a developer’s daily life. In order to best answer this question, I have written a non-exhaustive list of the benefits you will find:

  • Docker is fast. Unlike a virtual machine, your application can start in a few seconds and stop just as quickly.
  • Docker is multi-platform. You can launch your container on any system.
  • Containers can be built and destroyed faster than a virtual machine.
  • No more difficulties setting up your working environment. Once your Docker is configured, you will never have to reinstall your dependencies manually again. If you change computers or if an employee joins your company, you only have to give them your configuration.
  • You keep your work-space clean, as each of your environments will be isolated and you can delete them at any time without impacting the rest.
  • It will be easier to deploy your project on your server in order to put it online.

Now let’s create your first application

Now that you know what Docker is, it’s time to create your first application!

The purpose of this short tutorial is to create a Python program that displays a sentence. This program will have to be launched through a Dockerfile.

You will see, it’s not very complicated once you understand the process.

Note: You will not need to install Python on your computer. It will be up to the Docker environment to contain Python in order to execute your code.#### 1. Install Docker on your machine

For Ubuntu:

First, update your packages:

$ sudo apt update

Next, install docker with apt-get:

$ sudo apt-get install docker-ce

Finally, verify that Docker is installed correctly:

$ sudo docker run hello-world

2. Create your project

In order to create your first Docker application, I invite you to create a folder on your computer. It must contain the following two files:

  • A ‘main.py’ file (python file that will contain the code to be executed).
  • A ‘Dockerfile’ file (Docker file that will contain the necessary instructions to create the environment).

Normally you should have this folder architecture:

.
├── Dockerfile
└── main.py
0 directories, 2 files

3. Edit the Python file

You can add the following code to the ‘main.py’ file:

#!/usr/bin/env python3

print("Docker is magic!")

Nothing exceptional, but once you see “Docker is magic!” displayed in your terminal you will know that your Docker is working.

3. Edit the Docker file

Some theory: the first thing to do when you want to create your Dockerfile is to ask yourself what you want to do. Our goal here is to launch Python code.

To do this, our Docker must contain all the dependencies necessary to launch Python. A linux (Ubuntu) with Python installed on it should be enough.

The first step to take when you create a Docker file is to access the DockerHub website. This site contains many pre-designed images to save your time (for example: all images for linux or code languages).

In our case, we will type ‘Python’ in the search bar. The first result is the official image created to execute Python. Perfect, we’ll use it!

# A dockerfile must always start by importing the base image.
# We use the keyword 'FROM' to do that.
# In our example, we want import the python image.
# So we write 'python' for the image name and 'latest' for the version.
FROM python:latest

# In order to launch our python code, we must import it into our image.
# We use the keyword 'ADD' to do that.
# The first parameter 'main.py' is the name of the file on the host.
# The second parameter '/' is the path where to put the file on the image.
# Here we put the file at the image root folder.
ADD main.py /

# We need to define the command to launch when we are going to run the image.
# We use the keyword 'CMD' to do that.
# The following command will execute "python ./main.py".
CMD [ "python", "./main.py" ]

4. Create the Docker image

Once your code is ready and the Dockerfile is written, all you have to do is create your image to contain your application.

$ docker build -t python-test .

The ’-t’ option allows you to define the name of your image. In our case we have chosen ’python-test’ but you can put what you want.

5. Run the Docker image

Once the image is created, your code is ready to be launched.

$ docker run python-test

You need to put the name of your image after ‘docker run’.

There you go, that’s it. You should normally see “Docker is magic!” displayed in your terminal.

Useful commands for Docker

Before I leave you, I have prepared a list of commands that may be useful to you on Docker.

  • List your images.
$ docker image ls

  • Delete a specific image.
$ docker image rm [image name]

  • Delete all existing images.
$ docker image rm $(docker images -a -q)

  • List all existing containers (running and not running).
$ docker ps -a

  • Stop a specific container.
$ docker stop [container name]

  • Stop all running containers.
$ docker stop $(docker ps -a -q)

  • Delete a specific container (only if stopped).
$ docker rm [container name]

  • Delete all containers (only if stopped).
$ docker rm $(docker ps -a -q)

  • Display logs of a container.
$ docker logs [container name]

Before you go…

Thanks for reading! Do not hesitate to give me some feedback to improve my future articles in the comments below.

#docker #web-development

What is GEEK

Buddha Community

A beginner’s guide to Docker — how to create your first Docker application
Abigail betty

Abigail betty

1624226400

What is Bitcoin Cash? - A Beginner’s Guide

Bitcoin Cash was created as a result of a hard fork in the Bitcoin network. The Bitcoin Cash network supports a larger block size than Bitcoin (currently 32mb as opposed to Bitcoin’s 1mb).

Later on, Bitcoin Cash forked into Bitcoin SV due to differences in how to carry on its developments.

That’s Bitcoin Cash in a nutshell. If you want a more detailed review watch the complete video. Here’s what I’ll cover:

0:50 - Bitcoin forks
2:06 - Bitcoin’s block size debate
3:35 - Big blocks camp
4:26 - Small blocks camp
5:16 - Small blocks vs. big blocks arguments
7:05 - How decisions are made in the Bitcoin network
10:14 - Block size debate resolution
11:06 - Bitcoin cash intro
11:28 - BTC vs. BCH
12:13 - Bitcoin Cash (ABC) vs. Bitcoin SV
13:09 - Conclusion
📺 The video in this post was made by 99Bitcoins
The origin of the article: https://www.youtube.com/watch?v=ONhbb4YVRLM
🔺 DISCLAIMER: The article is for information sharing. The content of this video is solely the opinions of the speaker who is not a licensed financial advisor or registered investment advisor. Not investment advice or legal advice.
Cryptocurrency trading is VERY risky. Make sure you understand these risks and that you are responsible for what you do with your money
🔥 If you’re a beginner. I believe the article below will be useful to you ☞ What You Should Know Before Investing in Cryptocurrency - For Beginner
⭐ ⭐ ⭐The project is of interest to the community. Join to Get free ‘GEEK coin’ (GEEKCASH coin)!
☞ **-----CLICK HERE-----**⭐ ⭐ ⭐
Thanks for visiting and watching! Please don’t forget to leave a like, comment and share!

#bitcoin #blockchain #bitcoin cash #what is bitcoin cash? - a beginner’s guide #what is bitcoin cash #a beginner’s guide

Iliana  Welch

Iliana Welch

1595249460

Docker Explained: Docker Architecture | Docker Registries

Following the second video about Docker basics, in this video, I explain Docker architecture and explain the different building blocks of the docker engine; docker client, API, Docker Daemon. I also explain what a docker registry is and I finish the video with a demo explaining and illustrating how to use Docker hub

In this video lesson you will learn:

  • What is Docker Host
  • What is Docker Engine
  • Learn about Docker Architecture
  • Learn about Docker client and Docker Daemon
  • Docker Hub and Registries
  • Simple demo to understand using images from registries

#docker #docker hub #docker host #docker engine #docker architecture #api

Shubham Ankit

Shubham Ankit

1563259974

A beginner’s guide to Docker — how to create your first Docker application

After a short introduction on what Docker is and why to use it, you will be able to create your first application with Docker.

What is Docker?

Docker is a free software developed by Docker Inc. It was presented to the general public on March 13, 2013 and has become since that day a must in the world of IT development.

It allows users to create independent and isolated environments to launch and deploy its applications. These environments are then called containers.

This will let the developer run a container on any machine.

As you can see, with Docker, there are no more dependency or compilation problems. All you have to do is launch your container and your application will launch immediately.

But, is Docker a virtual machine?

Here is one of the most asked question about Docker. The answer is: actually, not quite.

It may look like a virtual machine at first but the functionality is not the same.

Unlike Docker, a virtual machine will include a complete operating system. It will be independent and act like a computer.

Docker will only share the resources of the host machine in order to run its environments.

Why use Docker as a developer?

This tool can really change a developer’s daily life. In order to best answer this question, I have written a non-exhaustive list of the benefits you will find:

  • Docker is fast. Unlike a virtual machine, your application can start in a few seconds and stop just as quickly.
  • Docker is multi-platform. You can launch your container on any system.
  • Containers can be built and destroyed faster than a virtual machine.
  • No more difficulties setting up your working environment. Once your Docker is configured, you will never have to reinstall your dependencies manually again. If you change computers or if an employee joins your company, you only have to give them your configuration.
  • You keep your work-space clean, as each of your environments will be isolated and you can delete them at any time without impacting the rest.
  • It will be easier to deploy your project on your server in order to put it online.

Now let’s create your first application

Now that you know what Docker is, it’s time to create your first application!

The purpose of this short tutorial is to create a Python program that displays a sentence. This program will have to be launched through a Dockerfile.

You will see, it’s not very complicated once you understand the process.

Note: You will not need to install Python on your computer. It will be up to the Docker environment to contain Python in order to execute your code.#### 1. Install Docker on your machine

For Ubuntu:

First, update your packages:

$ sudo apt update

Next, install docker with apt-get:

$ sudo apt-get install docker-ce

Finally, verify that Docker is installed correctly:

$ sudo docker run hello-world

2. Create your project

In order to create your first Docker application, I invite you to create a folder on your computer. It must contain the following two files:

  • A ‘main.py’ file (python file that will contain the code to be executed).
  • A ‘Dockerfile’ file (Docker file that will contain the necessary instructions to create the environment).

Normally you should have this folder architecture:

.
├── Dockerfile
└── main.py
0 directories, 2 files

3. Edit the Python file

You can add the following code to the ‘main.py’ file:

#!/usr/bin/env python3

print("Docker is magic!")

Nothing exceptional, but once you see “Docker is magic!” displayed in your terminal you will know that your Docker is working.

3. Edit the Docker file

Some theory: the first thing to do when you want to create your Dockerfile is to ask yourself what you want to do. Our goal here is to launch Python code.

To do this, our Docker must contain all the dependencies necessary to launch Python. A linux (Ubuntu) with Python installed on it should be enough.

The first step to take when you create a Docker file is to access the DockerHub website. This site contains many pre-designed images to save your time (for example: all images for linux or code languages).

In our case, we will type ‘Python’ in the search bar. The first result is the official image created to execute Python. Perfect, we’ll use it!

# A dockerfile must always start by importing the base image.
# We use the keyword 'FROM' to do that.
# In our example, we want import the python image.
# So we write 'python' for the image name and 'latest' for the version.
FROM python:latest

# In order to launch our python code, we must import it into our image.
# We use the keyword 'ADD' to do that.
# The first parameter 'main.py' is the name of the file on the host.
# The second parameter '/' is the path where to put the file on the image.
# Here we put the file at the image root folder.
ADD main.py /

# We need to define the command to launch when we are going to run the image.
# We use the keyword 'CMD' to do that.
# The following command will execute "python ./main.py".
CMD [ "python", "./main.py" ]

4. Create the Docker image

Once your code is ready and the Dockerfile is written, all you have to do is create your image to contain your application.

$ docker build -t python-test .

The ’-t’ option allows you to define the name of your image. In our case we have chosen ’python-test’ but you can put what you want.

5. Run the Docker image

Once the image is created, your code is ready to be launched.

$ docker run python-test

You need to put the name of your image after ‘docker run’.

There you go, that’s it. You should normally see “Docker is magic!” displayed in your terminal.

Useful commands for Docker

Before I leave you, I have prepared a list of commands that may be useful to you on Docker.

  • List your images.
$ docker image ls

  • Delete a specific image.
$ docker image rm [image name]

  • Delete all existing images.
$ docker image rm $(docker images -a -q)

  • List all existing containers (running and not running).
$ docker ps -a

  • Stop a specific container.
$ docker stop [container name]

  • Stop all running containers.
$ docker stop $(docker ps -a -q)

  • Delete a specific container (only if stopped).
$ docker rm [container name]

  • Delete all containers (only if stopped).
$ docker rm $(docker ps -a -q)

  • Display logs of a container.
$ docker logs [container name]

Before you go…

Thanks for reading! Do not hesitate to give me some feedback to improve my future articles in the comments below.

#docker #web-development

Iliana  Welch

Iliana Welch

1597368540

Docker Tutorial for Beginners 8 - Build and Run C++ Applications in a Docker Container

Docker is an open platform that allows use package, develop, run, and ship software applications in different environments using containers.
In this course We will learn How to Write Dockerfiles, Working with the Docker Toolbox, How to Work with the Docker Machine, How to Use Docker Compose to fire up multiple containers, How to Work with Docker Kinematic, Push images to Docker Hub, Pull images from a Docker Registery, Push stacks of servers to Docker Hub.
How to install Docker on Mac.

#docker tutorial #c++ #docker container #docker #docker hub #devopstools

August  Murray

August Murray

1615139520

A beginner’s guide to deploying a Docker application to production using Docker Compose

In this lesson, we are going to learn how Docker Compose works and how it can be used to deploy & manage multiple containers in the production environment.

In the previous lessons, we discussed the basics of Docker. We learned the anatomy of Docker containers, the structure of a Dockerfile, how to create images, how to manage containers, etc. This is just the basic information we need to know in order to operate Docker.

If our application is as simple as an HTTP server, we can run it inside a single Docker container. You can create a custom Docker image, copy the application code to the image, and run a container from it. You can mount a volume for persistent data storage and bind a port on the host to the port on the container to make your service public. That’s it. After that, we would need to manually monitor the container in case it goes down.

However, in reality, our application is made up of different services. For example, we might have a frontend service that serves the web application, a backend service that provides a REST API to the frontend, and a database service that stores the user data.

These services can be dependent on each other. For example, the frontend service depends on the backend service and the backend service depends on the database service. Unless we have all the services up and running, our application won’t function properly. They might need to be started in the right order for things to go well.

Doing this manually is cumbersome. Not everyone on your team will have the context of the entire application. It’s a big metadata to carry and you can’t afford to mess things up. You need some sort of orchestration tool to automatically manage your services. You want this tool to configure your services, manage startup and shutdown as well as handle failures. This is where Docker Compose comes in.

#docker-compose #devops #continuous-integration #docker #software-development