Read Part I here
- Installing Docker
Download docker from the official website for your platform.
SignUP for Docker Hub. Docker Hub is an online repository of container images made by the official vendors or the community that you can use as a template to build your own application and save them as new containers and share them back with the community.
2. Launch Docker application.
3. Go to Docker Hub and search for Ubuntu
4. Scroll down and look for the tags that you want to pull down from the docker hub to your local machine.
5. Basic Docker CLI
Download the 21.04 version. and the CLI to do so is
docker pull ubuntu:21.04
OR
docker pull ubuntu:hirsute
OR
docker pull ubuntu:rolling
If you look at the bottom, there are 2 ubuntu images with 21.04 and a hirsute tag. They are the same images but since I downloaded them with different tag names, they show up separately. So we will delete one of them.
At this step, we have a ubuntu docker image but not a container. The image needs to be first containerized before you can run it and access it to build your app inside it. To list all containers, we can use “docker ps -a”
There is no ubuntu container at the moment.
Let’s run the image to build a container out of it.
— name flag is used to name your container with a custom name. If you don’t specify a name, docker will automatically generate a name and assign it to your container. There are a ton of other flags that you can use while creating a container that will determine the behavior of that container.
- -d —- run in detached mode as a background service
- -p —- forward the ports between container and the host operating system
- -i —– Keep STDIN open even if not attached.
- -t —– tty session with the container
- -V —- mount the local partition with container partition
-it means to keep the session open into the container the moment the container is created.
Execute a command immediately after the container is created. Usually done for some initialization scripts
You can also mount volumes between the host machine and the container.
I am currently inside the docker_demo_1 folder and it’s empty. With the above command using the -v flag. I am trying to mount the current working directory with the/usr/src folder inside the container.
Now you can exchange files to and fro from the container and the host operating system.
In the next part of this series, we will build a python script inside this docker container and build the image from that container to distribute.
3 thoughts on “Docker for Network Engineers Part II – Installation and Basic Usage”