// see versions in shell docker --version docker-compose --version docker-machine --version
Open a command-line terminal, and run some Docker commands to verify that Docker is working as expected. Some good commands to try are docker version to check that you have the latest release installed, and docker ps and docker run hello-world to verify that Docker is running.
docker version docker ps docker run hello-world
To start a Dockerized web server:
docker run -d -p 80:80 --name webserver nginx
Run docker ps
while your web server is running to see details on the webserver container.
As an alternative to using Docker Hub to store your public or private images or Docker Trusted Registry, you can use Docker to set up your own insecure registry. Add URLs for insecure registries and registry mirrors on which to host your images.
Docker for Mac will detect HTTP/HTTPS Proxy Settings and automatically propagate these to Docker and to your containers. For example, if you set your proxy settings to http://proxy.example.com, Docker will use this proxy when pulling containers.
You can decide which directories on your Mac to share with containers.
Add a Directory - Click + and navigate to the directory you want to add.
Click Apply & Restart to make the directory available to containers using Docker’s bind mount (-v) feature.
There are some limitations on the directories that can be shared:
They cannot be a subdirectory of an already shared directory. They cannot already exist inside of Docker.
Docker for Mac can also be uninstalled using a command-line terminal:
(mdfind Docker.app)/Contents/MacOS/Docker --uninstall
To activate bash completion, these files need to be copied or symlinked to your bash_completion.d directory. For example, if you use Homebrew:
cd /usr/local/etc/bash_completion.d ln -s /Applications/Docker.app/Contents/Resources/etc/docker.bash-completion ln -s /Applications/Docker.app/Contents/Resources/etc/docker-machine.bash-completion ln -s /Applications/Docker.app/Contents/Resources/etc/docker-compose.bash-completion
docker ps -a
Breakdown of docker run hello-world
An image is a filesystem and parameters to use at runtime. It doesn’t have state and never changes. A container is a running instance of an image. When you ran the command, Docker Engine:
checked to see if you had the hello-world software image downloaded the image from the Docker Hub (more about the hub later) loaded the image into the container and “ran” it Depending on how it was built, an image might run a simple, single command and then exit. This is what Hello-World did.
A Docker image, though, is capable of much more. An image can start software as complex as a database, wait for you (or someone else) to add data, store the data for later use, and then wait for the next person.
Who built the hello-world software image though? In this case, Docker did but anyone can. Docker Engine lets people (or companies) create and share software through Docker images. Using Docker Engine, you don’t have to worry about whether your computer can run the software in a Docker image — a Docker container can always run it.
$ docker run mendlik/docker-whalesay
$ docker run mendlik/docker-whalesay "Your message"
$ docker run -it --entrypoint /bin/bash mendlik/docker-whalesay
docker images
context
for the build. The context just means it contains all the things you need to build your image.touch Dockerfile
Open this file, and add...
FROM docker/whalesay:latest
The FROM keyword tells Docker which image your image is based on. Whalesay is cute and has the cowsay program already, so we’ll start there.
Add RUN apt-get -y update && apt-get install -y fortunes
Now, to build...
docker build -t docker-whale .
The docker build -t docker-whale . command takes the Dockerfile in the current directory, and builds an image called docker-whale on your local machine. The command takes about a minute and its output looks really long and complex.
Once it is built, you can run it using the docker run <name>
command!