Docker Debian Based Image Build and Creating Container From The Image

Umut Tekin
2 min readJun 22, 2022

I have been using docker to create test environments for a couple of years. It is easy to manage, fast, flexible and disposable at the end. It will be a short one. So, let’ s get start!

First of all, we need a plain “Dockerfile”. The content of the file is pretty brief.

cat Dockerfile

FROM debian:latest
RUN apt update -y && apt install vim systemctl iputils-ping init net-tools wget curl -y && apt-get clean all
EXPOSE 22
ENTRYPOINT ["/sbin/init"]
CMD ["systemctl"]

I am using latest version of the Debian distro. Then, installing a few default packages I always use. I am exposing “ssh” port 22 because sometimes I need to access via over ssh from other containers. An example: Swingbench In Docker Container. Of course, there are many other solutions to avoid exposing 22 port, such as setting everything in the same container. Yet, I like to seperate everything in the test environments.

At the end of the Dockerfile, we are running “/sbin/init systemctl” to set a default entrypoint.

ls -ltr Dockerfile
-rw-r — r — 1 umut UsersGrp 195 May 19 22:46 Dockerfile

Because the Dockerfile is in my current folder so I can execute this command(do not forget “.”(dot) at the end).

docker build -t myimage .

[+] Building 129.0s (6/6) FINISHED
=> [internal] load build definition from Dockerfile 1.2s
=> => transferring dockerfile: 234B 0.0s
=> [internal] load .dockerignore 0.9s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/debian:latest 4.8s
=> [1/2] FROM docker.io/library/debian:latest@sha256:3f1d6c17773a45c97bd8f158d665c9709d7b29ed7917ac934086ad96f92e4510 7.8s
=> => resolve docker.io/library/debian:latest@sha256:3f1d6c17773a45c97bd8f158d665c9709d7b29ed7917ac934086ad96f92e4510 0.1s
=> => sha256:3f1d6c17773a45c97bd8f158d665c9709d7b29ed7917ac934086ad96f92e4510 1.85kB / 1.85kB 0.0s
=> => sha256:f0203caaadfa5e8191aa8d75ad0b36c95c72543c33f76e48f0a4d9dec22d5a63 529B / 529B 0.0s
=> => sha256:4eacea30377a698ef8fbec99b6caf01cb150151cbedc8e0b1c3d22f134206f1a 1.46kB / 1.46kB 0.0s
=> => sha256:e756f3fdd6a378aa16205b0f75d178b7532b110e86be7659004fc6a21183226c 55.01MB / 55.01MB 3.9s
=> => extracting sha256:e756f3fdd6a378aa16205b0f75d178b7532b110e86be7659004fc6a21183226c 2.6s
=> [2/2] RUN apt update -y && apt install vim systemctl iputils-ping init net-tools wget curl lsb-release -y && apt-get clean all 113.1s
=> exporting to image 1.5s
=> => exporting layers 1.5s
=> => writing image sha256:0a555ef2b2d8b7a0ad1e707393ddb33b4457b97b88f4dc0fdd09aa6e8a2e038d 0.0s
=> => naming to docker.io/library/myimage 0.0s

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them

Now, we can list our image(s):

docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
myimage latest 0a555ef2b2d8 2 minutes ago 224MB

Create a container from “myimage”:

docker run — name test -d myimage
0f5149b864a2a5cc0bccfb9a51f2d57942a14b0e8a57706b0638c9d1d53e2839

Finally, we can run bash on our container:

docker exec -it test bash
root@0f5149b864a2:/# uname -a
Linux 0f5149b864a2 5.10.16.3-microsoft-standard-WSL2 #1 SMP Fri Apr 2 22:23:49 UTC 2021 x86_64 GNU/Linux
root@0f5149b864a2:/#

Our disposable test environment is ready for departure :). (Lately, I came back from a trip). You can use it for many purposes.

Thanks for reading!

--

--