Beforehand, please install Docker on your machine. If you use
macOS, I highly recommend using Docker for Mac1 version (my term is native version) instead of docker-machine because I’m using native version to demonstrate. In case you might wonder why, please read here.
Step 1 - Preparing
I start with ubuntu 16:04
Installing my desire components like
Making a default executable for my image with
Step 2 - Run it
What you need to do next is to change directory as same level as Dockerfile and run
docker build -t demo . then you can check
docker images to see your demo image is there.
What I Learnt
Finding instructions to build an image is usually annoying because some lines in Dockerfile may occur errors and a trial consumes time. To understand, suppose my Dockerfile had 3 lines, I observed an error had happened at last line. Obviously, I would have to fix, run and wait. As I mentioned, emotion is problematic hence I think about acceleration.
The fact is Docker caches preceding layers4 so I do follow suggestions from the best docker practices. But I want more than that so I have an idea which I will build on a correct images. It means I break Dockerfile into parts, for lines from beginning don’t cause error will be a correct one, rest of lines are on working Dockerfile. These parts have been connected by
For instance, correct part is
then I build and name it as based image
docker build -t mine:based .. Next I just focus on working part like
Eventually, everything is correct, I’m able to make a single final file.
Another thing, inside container of Ubuntu:16.04, you’re not to use
sudo at begining5, example
RUN apt-get update && apt-get install -y