[Docker] – Creating a Docker container with Fedora and a Docker installed inside

Following the steps.

1. Create a Dockerfile with the following content.

from fedora

RUN dnf install python-pip -y
RUN dnf -y install dnf-plugins-core
RUN dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
RUN dnf config-manager --set-disabled docker-ce-test
RUN dnf config-manager --set-disabled docker-ce-edge
RUN dnf install docker-ce -y
RUN pip install docker-compose

CMD ["systemctl","start","docker"]

2. Run the following command to build the image based on this Dockerfile.

$docker build -t fedora-docker-in-docker .

3. Create a bash file with the following content.

#!/bin/bash

docker run -d \
  --rm \
  --name fdid \
  -e=container=docker \
  --stop-signal=SIGRTMIN+3 \
  --cap-add=SYS_ADMIN \
  --security-opt=seccomp:unconfined \
  --privileged \
  -v /sys/fs/cgroup:/sys/fs/cgroup:ro \
  fedora-docker-in-docker \
  /sbin/init
  
docker exec -it fdid bash

4. Make the bash file an executable file as following.

$ chmod +x bash.sh

5. Execute the bash file created.

$ ./bash.sh
bc60239b64153519012e4a4bc340eedfea4f1eed3889c2860f52e4fdf1862503
[root@bc60239b6415 /]# 

Now you are inside of your fedora container with a docker instaled inside. Also, you will have permission to stop and start the docker inside of this container by running the following command for example.

$ systemctl stop docker

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s