Last Updated on by
How To Run Docker in Docker Container
Docker is the best containerization tool using which developers can easily package and run an application in a loosely isolated environment called a container. Using Docker, developers can also run numerous containers in parallel on a given host. One of the special features of Docker is that you can run its containers directly in the virtual machines.
One of the interesting concepts about Docker containers is that, you can possibly run Docker inside a Docker container. One possible use case to run docker inside a docker is by using CI pipeline technique. In this approach, once the code is build successfully, user has to build and push docker images to a container registry.
You can also run docker in docker by building Docker images with a VM. If in case, if you are using Jenkins docker based dynamic agents for your continuous integration or continuous deployment pipelines, then docker in docker comes as a must-have functionality. Know more in-depth about the Docker & other prominent tools in DevOps through our DevOps Training In Hyderabad program.
Run Docker in Docker Container-Using Dind Approach:
Dind approach is the best suited approach to run docker in docker container & this approach is only ideal if you intended to include containers & images inside the container. In this Dind method, a child container is created inside a container.
This is a simple straight forward approach that requires official docker image with dind tag. The dind image is then baked with required utilities for Docker to run inside a docker container.
The whole setup can be tested by using the following steps & you must also ensure to run the container in the privileged mode.
Step 1
In the first step you will be creating a container with the name ‘dind-test’ with ‘docker:dind’ image
docker run --privileged -d --name dind-test docker:dind
Step 2
You will be logging in to the container using exec.
docker exec -it dind-test /bin/sh
Step 3
After successfully logging into the container, execute the following docker command.
docker pull ubuntu
Step 4
In this step, you will be creating a Dockerfile inside test directory.
mkdir test && cd test
vi Dockerfile
Then simply compy the following docker file contents to test the image build from within the container.
FROM ubuntu:18.04
LABEL maintainer="Bibin Wilson "
RUN apt-get update && \
apt-get -qy full-upgrade && \
apt-get install -qy curl && \
apt-get install -qy curl && \
curl -sSL https://get.docker.com/ | sh
Now you can validate docker command-line instructions and image build.
Get to know more abut the other ways in which you can run Docker in a Docker container through experts guidance with our Kelly Technologies DevOps training program.