Docker Beginner's Guide
Docker has become widely used in companies and education institutions for its convenience and portability compared to virtual machines. I was actually “forced” to used Docker and honestly I hated to use it probably because of the steepness at the beginning of the learning curve.
Here I documented some of the problems I met during my work and the potential solutions to solve them.
I first learned how to use Docker from the official tutorials on the Docker website. It basically taught you how to set up a portable web application in Docker. For developed software shipments, it is perfectly fine to use Docker as an App. However, in terms of software development, which requires debugging and some auxiliary components other than the software itself, using Docker as a Virtual Machine might be better.
When I say use Docker as an app, I mean you can just run the docker and wait for the response as a software program. The Docker container has been preset with
CMD, and all some part of your auxiliary files might have already been copied to the Docker container. Because the Docker container has been set with
CMD, it will run instantly just like a software program.
$ docker run octave-image-processing
When I say use Docker as a virtual machine, I mean you develop software interactively in Docker as if you are in a computer system.
-it is used for interactive communication with the Docker container.
$ docker run -it octave-image-processing
-v for running container allows you to bound the local directories to the directories in the Docker container. This facilitates data streaming between the local computer and the Docker container.
$ docker run -it -v /mnt/data/leimao:/mnt -v /home/leimao:/home octave-image-processing
It should be noted that sometimes you do not have writing permissions to the local directories. In my case, I have two workstations, workstation
burning, with my login name
marine account has both reading and writing to both of the work stations. One of the hard drives of
alice was mounted to
marine account could also read and write on the hard drive of
alice that is mounted on the
alice does not allow an account named
root to write on the hard drive remotely. So in the Docker container of
burning, I do not have writing permission to the hard drive of
alice mounted on
alice sees me as
root, instead of
burning. In the Docker container of
alice, I can write to the hard drive because
alice know this
root is from
marine on the local machine.
Sometimes, you want to clean some Docker images to free more disk space.
To check all the images created on the computer:
$ docker images
For example, to delete
octave-image-processing created 3 hours ago using its
$ docker rmi --force 9296aabfaedd
--force because sometimes the container is still running on this image.
Sometimes, you will find some images with name
<none> that were images resulted of building failure. To remove them:
$ docker rmi $(docker images --filter "dangling=true" -q --no-trunc)
To build your own images, we have to use some base images from the Docker official repository or some third-party repositories.
Sometimes, to save the disk space, we would use the base image with a minimum size that is necessary for the environment. However, this sometimes will bring trouble.
For example, I had once wanted to install Python 3 and the latest Octave in the environment. I somehow chose a Python 3 image as my base image. Although I could still do
apt-get update and
apt-get install to install Octave, the Octave installed would be a very old version. The personal package archives (PPA) which usually provide the latest version of Octave would also be problematic to use. Later, I changed my base image from Python 3 to Ubuntu 16.04, I was able to use PPA to install the latest Octave without any problem. So I guess many utilities used in Ubuntu were missing in the Python 3 base images.
Dockerfile, sometime you might be confused between
ENV. This figure from Vladislav Supalov explained the difference very well.
Docker Beginner's Guide