Docker Community Forums

Share and learn in the Docker community.

Understanding docker, docker container, docker images

Hi,

I’m new to docker and wish to learn it. I have experience in FreeBSD Jail if that makes any difference. But to get me started, I would like to know one thing first.

In a FreeBSD Jail, I can connect to it via cli and execute FreeBSD commands like install server software (tomcat, mariadb etc). Basically do all the setup inside the jail to get the application up and running.

Can I also do this in a Docker Container? Run an empty Docker container and ssh to it and install all the software I need? Reason I’m asking is because I’m quite comfortable installing software myself via command line.

Appreciate any feedback.

Regards,
Allen

1 Like

Hello, @allensandiego !

I will admit that I too am also new to this, but from what I have gathered so far:

When setting up a Container, you can specify within a Dockerfile or a Docker-Compse .yml file, to have various applications installed when the Container is being spin up.

After spinning up the Container, you can access the Container via SSH (following this link is a good basic of how to get to that point:)

https://phase2.github.io/devtools/common-tasks/ssh-into-a-container/

There are many other means to access the Container as well, and if I remember correctly, most of them have to be setup/configured within the Dockerfile or Docker-Compose file.

Regarding entering into an empty Container, void of everything including a simple OS, I’m not sure about that. I think it still needs to have some OS/software inside the Container to allow you inside to add software. This question is for someone more knowledgeable than myself.

Sure you can do so but it’s as if you buy a car and push it instead of using the engine. Its not how you use it. :slight_smile:

The Idea behind docker is that you configure your Dockerfile to automatically build and image from its configuration, which includes all necessary software and config. If you would just start an empty docker container and install the required software via ssh, you would need to install the software over and over again if you spin up a new container. With a proper docker image you could spin up infinite amounts of containers and every container is already configured exactly as you want.

Basically instead of installing the software via ssh you just copy these commands in the dockerfile and docker handles the rest for you (a bit simplified explanation)

Hi @jjatinno ,

Thanks. I’ll give this a shot.

Also, I might have used the wrong term when I said empty container. Basically what I meant here it to have a container without any added software except for the OS pre-installed software. At least this way, I can still do apt install or wget inside the container. This is how I see docker container as of now since I don’t know much about it yet.

Thanks.

I did a bit of light reading on the docker file but I still find it a little bit confusing. I’m used to building shell scripts that do wget, then either dpkg or just do apt install line by line. I guess I just need to learn more about the syntax of the docker file.

Also, I still don’t understand. What comes first? Is it the container or the image? Do I build a container from a docker file then build an image from the finished container or do I build an image from a docker file and build a container from that image?

Also, I still don’t understand. What comes first? Is it the container or the image? Do I build a container from a docker file then build an image from the finished container or do I build an image from a docker file and build a container from that image?

Technically, the Image comes first.

Your Docker File creates a Container of a chosen Image.

The Docker File is like a Blueprint for the construction of your Container.

Each line within a Docker File will add a new Layer to the Container you are creating.

Each line added can be any command you would normally use in Linux (or whatever), with some limitations (which I can’t go into detail here, as I am still learning them myself [Docker, though awesome, is still pretty confusing in how it describes/explains itself]).

The following is an example of a Dockerfile I am currently using to build a Container from an Image:

FROM ubuntu:20.10

RUN apt update && apt install openssh-server sudo openvpn ser2net network-manager cron nano -y
RUN mkdir /etc/new-dir
RUN mkdir /etc/new-dir/sub-dir

COPY local-dir/certs/* /etc/new-dir/sub-dir
COPY local-dir/config_dir/* /etc/new-dir
COPY local-dir/directory /usr/bin/directory

ADD local-dir/crontab.txt /var/spool/cron/crontabs/root

RUN chmod 0644 /var/spool/cron/crontabs/root
RUN touch /var/log/cron.log

CMD cron && tail -f /var/log/cron.log

The first line of the following quote is telling the Dockerfile what Image to base the Container off of.
The lines following that one tell the Dockerfile to run those commands to/within the Container.
Each line is providing a new Layer to your Container, slowly building it to the point where you want to begin running your specific tests.
When your Dockerfile finishes putting together the Container, it will begin at the point of the last line in your Dockerfile, and should contain/run everything that you filled it with before that point.