From: https://docker-curriculum.com/
一、docker常见的命令
- 从远程Pull image:
$ docker pull busybox
- List images:
$ docker images
- Docker Run:
# When you call run, the Docker client finds the image (busybox in this case), loads up the container and then runs a command in that container. When we run docker run busybox, we didn't provide a command, so the container booted up, ran an empty command and then exited.
$ docker run busybox
$ docker run busybox echo "hello from busybox"
# -it flags attaches us to an interactive tty in the container
$ docker run -it busybox sh
$ docker run --help
# -d will detach our terminal , -P will publish all exposed ports to random ports
$ docker run -d -P --name static-site prakhar1989/static-site
$ docker run -d --name sonarqube -e SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true -p 9000:9000 sonarqube:latest
- List all containers that are currently running
$ docker ps
#和 docker ps一样
$ docker container ls
# list all containers including exited status.
$ docker ps -a
- Stop 容器:
# 停止某个container
$ docker container stop es
$ docker stop [containerID or name]
- Docker Start容器
当container退出后,状态为Exited, 这时可以重启这个container。如果docker rm 这个container,则container中所作的变更和数据都没了,所以如果打算继续用这个container中的数据,就不要rm container然后重新run,而要重新Start这个容器。如:
$ docker ps -a
$ docker run [container ID or Name]
7. Delete Containers 容器
虽然container退出了,但是还是可能占用磁盘空间的。
$ docker rm 305297d7a235 ff0a5c3750b9
$ docker rm $(docker ps -a -q -f status=exited)
$ docker container prune
- Delete Images 镜像:
$ docker rmi [OPTIONS] IMAGE [IMAGE...]
$ docker rmi -f prakhar1989/static-site
-f :强制删除, 即便被container引用了
- Docker pull http不安全镜像
默认docker会用Https连接镜像的,但是如果是自己私下搭建的http仓库,就需要在docker中配置下,可以配置:daemon.json 文件,或打开Docker Desktop,点击setting齿轮,选择Docker Engine,在配置中添加insecure-registries,如:"insecure-registries": ["10.0.2.86"]
另外如果是私有的,还需要先登录。先在terminal命令行窗口执行:docker login [harbor地址], 输入用户名密码。
10. Docker image 导出
$ docker save [Image name] 或 :docker save busybox > busybox.tar
二、docker network:
$ docker network ls
其中有个bridge的网络,The bridge network is the network in which containers are run by default.
$ docker network inspect bridge
In terms of Docker, a bridge network uses a software bridge which allows containers connected to the same bridge network to communicate, while providing isolation from containers which are not connected to that bridge network. 除了bridge网络,还有别的类型的网络可以创建。
对于新创建的网络,containers can not only communicate by IP address, but can also resolve a container name to an IP address. This capability is called automatic service discovery
三、docker的类型:
- Base images are images that have no parent image, usually images with an OS like ubuntu, busybox or debian.
- Child images are images that build on base images and add additional functionality.
- Official images: 名称上通常是一个单词,而User Images名称上通常是 user/image-name.
四、build my Image:
- 创建 Dockerfile 文件
- docker build -t yourusername/catnip .
五、Docker Compose:
Compose is a tool that is used for defining and running multi-container Docker apps in an easy way. It provides a configuration file called docker-compose.yml that can be used to bring up an application and the suite of services it depends on with just one command. 这个yaml文件其实就是描述了怎么从image运行container,service之间的依赖,一些运行参数等。Docker-compose 启动的时候会自动创建一个network,并且把service都加入到这个网络中,可以上面的命令inspect这个网络查看其中包含的containers。
# 启动,-d代表是detached方式
$ docker-compose up -d
$ docker-compose down -v
标签:busybox,container,基础,命令,images,run,docker,Docker From: https://www.cnblogs.com/saaspeter/p/17877452.html