Docker basics
1.Learn about images and containers
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:
1.checked to see if you had the hello-world software image 2.downloaded the image from the Docker Hub (more about the hub later)
3.loaded the image into the container and “ran” it
2.Find and run the whalesay image
People all over the world create Docker images. You can find these images by browsing the Docker Hub.这么方便?
3.Build your own image
Step 1: Write a Dockerfile
A Dockerfile is a recipe which describes the files, environment, and commands that make up an image.
Remember that if you are using macOS or Windows, you are still creating an image which runs on Linux.
Step 2: Build an image from your Dockerfile
Step 3: Learn about the build process
Step 4: Run your new docker-whale
4.Create a Docker Hub account and repository
5.Tag, push, and pull your image
Define and deploy your app
1.Sample app overview
之前我们用Dockerfile来build,run whalesay app.
For this tutorial, the images are pre-built, and we use a stack file instead of a Dockerfile to specify the images. When we deploy, each image will run as a service in a container (or in multiple containers, for those that have replicas defined to scale the app).一个docker-stack.yml参考例子:
version: "3"
services:
redis:
image: redis:alpine
ports:
- "6379"
networks:
- frontend
deploy:
replicas: 2
update_config:
parallelism: 2
delay: 10s
restart_policy:
condition: on-failure
db:
image: postgres:9.4
volumes:
- db-data:/var/lib/postgresql/data
networks:
- backend
deploy:
placement:
constraints: [node.role == manager]
vote:
image: dockersamples/examplevotingapp_vote:before
ports:
- 5000:80
networks:
- frontend
depends_on:
- redis
deploy:
replicas: 2
update_config:
parallelism: 2
restart_policy:
condition: on-failure
result:
image: dockersamples/examplevotingapp_result:before
ports:
- 5001:80
networks:
- backend
depends_on:
- db
deploy:
replicas: 1
update_config:
parallelism: 2
delay: 10s
restart_policy:
condition: on-failure
worker:
image: dockersamples/examplevotingapp_worker
networks:
- frontend
- backend
deploy:
mode: replicated
replicas: 1
labels: [APP=VOTING]
restart_policy:
condition: on-failure
delay: 10s
max_attempts: 3
window: 120s
placement:
constraints: [node.role == manager]
visualizer:
image: dockersamples/visualizer:stable
ports:
- "8080:8080"
stop_grace_period: 1m30s
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
deploy:
placement:
constraints: [node.role == manager]
networks:
frontend:
backend:
volumes:
db-data:
2.Set up Dockerized machines
3.Create a swarm
4.Deploy the application