Docker crash course

文章目录

Docker crash course1. What and Why of Docker?2.1 What2.2 What problem does it solve?2.2.1 before containers2.1.2 with containers

2. Docker vs Virtual Machines2.1 Difference2.2 Benefits

3. Install docker locally4. Images vs Containers5. Public and Private Registries6. Main Docker commands - pull,run,start,stop,logs,build6.1 pull & run6.2 start & stop

7. Public and private Docker registries8. Registry vs Repository9. Create own image (Dockerfile)9.1 Dockerfile - Build instruction9.2 Build image9.3 Run as Docker container9.4 Docker UI Client

10. Image Versioning11. Docker Compose12. Docker Workflow Big Picture

1. What and Why of Docker?

2.1 What

2.2 What problem does it solve?

2.2.1 before containers

Development process before containers? If your app uses 10 services, each developer needs to install these 10 services.

Development process:

Installations and configurations done directly on server’s OSDependency version conflicts etc.

2.1.2 with containers

Development process with containers? Standardizes process of running any services on any local dev environment.

Development process:

Install Docker runtime on the serverRun Docker command to fetch and run Docker artifacts.

2. Docker vs Virtual Machines

2.1 Difference

docker

contains the OS application layer - vertualize complete OSservices and apps installed on top that layer

2.2 Benefits

most containers are Linux basedOriginally built for Linux OS

upgrade –

3. Install docker locally

4. Images vs Containers

docker images

docker ps = list running contaniers

5. Public and Private Registries

How do we get these images?

6. Main Docker commands - pull,run,start,stop,logs,build

6.1 pull & run

Pull Docker Hub registry (docker.io) is used by default.

docker pull {name}:{tag} = Pull an image from a registry

docker images

Run

docker run {name}:{tag} = creates a container from given images and starts it

docker ps

docker generates a random name for the container automatically if you don’t specify onedocker pulls image automatically, if it doesn’t find it locally.

docker -d = runs container in background and prints the container ID

you may still want to see the logs,which can be useful for debugging etc.

docker logs {container} = view logs from service running inside the container.

give a name --name

docker run --name web-app -d -p 9000:80 nginx:1.23

Port Binding

localhost:80 cannot be reached

only run with additional tag:

docker stop {container} = stop one or more running containers

-p or --publish = pubish a container's port to the host

-p {HOST_PORT}:{CONTAINER_PORT}

all in all

docker run -d -p 9000:80 niginx:1.23

6.2 start & stop

docker ps only list the running containers. To list all containers (stopped and running) by using flag -a or --all

docker ps -a

stop

docker stop {containerID}

start

docker start {containerID} = start one or more stopped containers

logs

docker logs {containerID/NAME}

7. Public and private Docker registries

8. Registry vs Repository

9. Create own image (Dockerfile)

9.1 Dockerfile - Build instruction

CMD ["node", "server.js"]

9.2 Build image

docker build {path} = Builds a Docker image from a Dockerfile

Sets a name and optionally a tag in the “name:tag” format

docker build -t node-app:1.0 .

9.3 Run as Docker container

9.4 Docker UI Client

10. Image Versioning

“latest” tag mostly refers to the newest release.

11. Docker Compose

12. Docker Workflow Big Picture

How Docker fits in the complete development and development process?

相关链接

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。