Docker基础
文章目录
Docker
关键概念
docker engine和docker machine的区别
简言之,平时说的docker是指docker engine,其是一个客户端-服务端的应用。而docker machine是一个可以安装docker engine的工具。
registry
A registry is a collection of repositories, and a repository is a collection of images。An account on a registry can create many repositories. The
docker
CLI uses Docker’s public registry by default.
基本配置问题
- docker hub镜像加速
登陆阿里云,找到镜像中心,镜像加速器,就可以得到加速地址。windows下直接邮件settings即可,在daemon一栏中有Registry mirrors一栏。
windows docker share drive,输入微软账户密码即可。
注意dockerfile的换行符一定要用
LF
,不然会有奇奇怪怪的问题。
get start
orientation
An image is an executable package that includes everything needed to run an application–the code, a runtime, libraries, environment variables, and configuration files.
A container is a runtime instance of an image–what the image becomes in memory when executed (that is, an image with state, or a user process).
docker ps
列出正在运行的container。
|
|
container
- windows下
ctrl-c
不能停止正在运行的容器,需要使用docker container stop <Container NAME or ID>
|
|
services
|
|
docker-compose
The Compose file is a YAML file defining services, networks and volumes.
Tip: You can use either a
.yml
or.yaml
extension for this file. They both work.
docker compose文件主要包括三大部分:
- services
- networks
- volumes
A service definition contains configuration that is applied to each container started for that service, much like passing command-line parameters to
docker container create
. Likewise, network and volume definitions are analogous todocker network create
anddocker volume create
.
使用docker compose -f xx.yml up
命令启动,这里-f
指定当前使用的compose文件名,默认docker-compose.yml
。
You can stop your containers using the stop or down command, but the down command does more than stopping your containers.
The docker-compose stop
command will stop your containers, but it won’t remove them.
The docker-compose down
command will stop your containers, but it also removes the stopped containers as well as any networks that were created. 此外多加一个-v
选项可以把volumes也一同删除。
restart a single container with docker-compose
|
|
上述命令只会“原样”重启容器,而不会应用更改的任何设置。 可以使用如下命令重新构建某个容器,并应用对配置文件的修改。
|
|
docker-compose up for only certain contains
只需要指定服务名即可。
|
|
Docker Detached Mode
容器默认是foreground mode
,使用-d
选项来进入detached mode
。
You can start a docker container in detached mode with a
-d
option. So the container starts up and run in background. That means, you start up the container and could use the console after startup for other commands.The opposite of detached mode is foreground mode. That is the default mode, when
-d
option is not used. In this mode, the console you are using to executedocker run
will be attached to standard input, output and error. That means your console is attached to the container’s process.In detached mode, you can follow the standard output of your docker container with
docker logs -f <container_ID>
.
ps:
使用docker container start xx
启动一个已经停止的容器时,默认是detached mode,-a
选项是foreground mode。
文章作者 mayuan
上次更新 2019-11-20