Launch a container in docker. Further, launch a container then install docker in it and again launch a container in containerized docker.

Nishant Saini
2 min readDec 29, 2020

--

In this article, We will discuss Launching a container in docker. Further, launch a container then install docker in it and again launch a container in containerized docker.

To accomplish this, you’ll need to have Docker already installed on your host machine. If you haven’t installed Docker yet, you can follow the official Docker installation guide for your respective operating system: https://docs.docker.com/get-docker/

Once Docker is installed on your host machine, follow these steps to launch a container, then install Docker inside it, and finally launch a container within that containerized Docker:

Step 1: Launch a Container Let’s start by launching a simple container. We’ll use the nginx image as an example, which is a popular web server.

# Launch a container using the nginx image
docker run -d — name my-nginx nginx

Step 2: Install Docker inside the Container Now, we’ll enter the container you just launched and install Docker inside it.

# Enter the container
docker exec -it my-nginx /bin/bash

# Update the package list and install some prerequisites
apt-get update
apt-get install -y apt-transport-https ca-certificates curl software-properties-common

# Add Docker’s official GPG key
curl -fsSL
https://download.docker.com/linux/ubuntu/gpg | gpg — dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

# Add the Docker repository
echo “deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg]
https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable” | tee /etc/apt/sources.list.d/docker.list > /dev/null

# Install Docker inside the container
apt-get update
apt-get install -y docker-ce

# Exit the container
exit

Step 3: Launch a Container in the Containerized Docker After installing Docker inside the container, you can now launch another container within that containerized Docker environment.

# Enter the container again
docker exec -it my-nginx /bin/bash

# Launch another container inside the containerized Docker
docker run -d — name my-container-in-container nginx

# Exit the container
exit

That’s it! Now you have a container (my-nginx) running on your host machine, which contains Docker itself. Inside that container, you've launched another container (my-container-in-container) using Docker.

--

--

Nishant Saini
Nishant Saini

Written by Nishant Saini

0 Followers

RedHat Certified Engineer (RHCE) | AWS Academy Graduate | DevOps Enthusiast

No responses yet