-
Notifications
You must be signed in to change notification settings - Fork 0
Docker
[Docker Explained: Using Dockerfiles to Automate Building of Images] (https://www.digitalocean.com/community/tutorials/docker-explained-using-dockerfiles-to-automate-building-of-images) @DigitalOcean
[Dockerfile reference] (https://docs.docker.com/engine/reference/builder/) @Docs.Docker
##Docker Machine
docker-machine ls
docker-machine Start/stop [NAME/S]
docker run hello-world
Run docker ps -a
to show all containers on the system.
The command docker ps
shows only currently running containers.
The command docker images
lists all the images on your local system
You can specify a repository and tag at which to save the new image if the build succeeds:
$ docker build -t shykes/myapp .
# Stop ALL running containers
docker stop $(docker ps -a -q)
# Remove all build containers
docker rm $(docker ps -a -q)
# Remove all saved images (that is remove base images downloaded and cached)
docker rmi $(docker images -q)
##Build your own image
####Dockerfile
- Go to your command terminal window.
- Make a new directory by typing mkdir mydockerbuild and pressing RETURN.
mkdir mydockerbuild
This directory serves as the “context” for your build. The context just means it contains all the things you need to build your image. - Change to your new directory.
cd mydockerbuild
Right now the directory is empty. - Create a Dockerfile in the directory by typing touch Dockerfile and pressing RETURN.
touch Dockerfile
The command appears to do nothing but it actually creates the Dockerfile in the current directory. - Open the
Dockerfile
in a visual text editor like Atom or Sublime, or a text based editor like vi, or nano (https://www.nano-editor.org/). - Add a line to the file like this:
FROM docker/whalesay:latest
TheFROM
keyword tells Docker which image your image is based on. Whalesay is cute and has the cowsay program already, so we’ll start there. - Now, add the fortunes program to the image.
RUN apt-get -y update && apt-get install -y fortunes
The fortunes program has a command that prints out wise sayings for our whale to say. So, the first step is to install it. This line installs the software into the image. - Once the image has the software it needs, you instruct the software to run when the image is loaded.
CMD /usr/games/fortune -a | cowsay
This line tells thefortune
program to pass a nifty quote to thecowsay
program. - Check your work, your file should look like this:
FROM docker/whalesay:latest RUN apt-get -y update && apt-get install -y fortunes CMD /usr/games/fortune -a | cowsay
- Save and close your Dockerfile.
At this point, you have all your software ingredients and behaviors described in a Dockerfile. You are ready to build a new image.
####Build image from Dockerfile
- At the command line, make sure the Dockerfile is in the current directory by typing
cat Dockerfile
- Now, build your new image by typing
docker build -t docker-whale .
##Run interactive container
docker run -t -i ubuntu /bin/bash
docker run
runs a container.
ubuntu
is the image you would like to run.
-t
flag assigns a pseudo-tty or terminal inside the new container.
-i
flag allows you to make an interactive connection by grabbing the standard in (STDIN) of the container.
/bin/bash
launches a Bash shell inside our container.
exit
command or Ctrl-D
to exit the interactive shell.
##Troubleshooting
[@Docks.Docker.com] (https://docs.docker.com/toolbox/faqs/troubleshoot/)