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:
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.