docker_practice/appendix/faq/README.md

222 lines
10 KiB
Go
Raw Permalink Normal View History

2016-12-10 17:00:25 +08:00
#
##
2017-11-24 00:29:51 +08:00
###
使 `docker image prune`
2016-12-10 17:00:25 +08:00
###
2017-11-24 00:29:51 +08:00
2016-12-10 17:00:25 +08:00
使 `docker run IMAGE env`
###
2017-11-24 00:29:51 +08:00
Docker `/var/lib/docker/` `overlay2` `containers` `image` `overlay2`
2016-12-10 17:00:25 +08:00
### Docker
2017-11-24 00:29:51 +08:00
2016-12-10 17:00:25 +08:00
* `alpine`
2017-11-24 00:29:51 +08:00
2016-12-10 17:00:25 +08:00
*
2017-11-24 00:29:51 +08:00
2016-12-10 17:00:25 +08:00
*
2017-11-24 00:29:51 +08:00
2016-12-10 17:00:25 +08:00
* 使
2017-11-24 00:29:51 +08:00
2016-12-10 17:00:25 +08:00
*
2017-11-24 00:29:51 +08:00
2016-12-10 17:00:25 +08:00
* 使 Dockerfile .dockerignore 使
2019-01-06 09:50:03 +08:00
[Dockerfile ](../best_practices.md)
2017-11-24 00:29:51 +08:00
2016-12-10 17:00:25 +08:00
### pull http_proxy
2017-11-24 00:29:51 +08:00
2016-12-10 17:00:25 +08:00
Docker `export http_proxy="http://<PROXY_HOST>:<PROXY_PORT>"` Docker
##
2017-11-24 00:29:51 +08:00
### 退 docker container ls
2017-11-24 00:29:51 +08:00
退exited `docker container ls -a` `docker start`
2016-12-10 17:00:25 +08:00
2017-11-24 00:29:51 +08:00
###
使 `docker stop $(docker container ls -q)`
2016-12-10 17:00:25 +08:00
2017-11-24 00:29:51 +08:00
###
使 `docker container prune`
2016-12-10 17:00:25 +08:00
### PID
2017-11-24 00:29:51 +08:00
使
```bash
docker inspect --format '{{ .State.Pid }}' <CONTAINER ID or NAME>
```
2016-12-10 17:00:25 +08:00
### IP
2017-11-24 00:29:51 +08:00
使
```bash
docker inspect --format '{{ .NetworkSettings.IPAddress }}' <CONTAINER ID or NAME>
```
2016-12-10 17:00:25 +08:00
### IP IP
2017-11-24 00:29:51 +08:00
使使 IP
```bash
$ docker network create -d bridge --subnet 172.25.0.0/16 my-net
$ docker run --network=my-net --ip=172.25.3.3 -itd --name=my-container busybox
```
2016-12-10 17:00:25 +08:00
### 退
2017-11-24 00:29:51 +08:00
2016-12-10 17:00:25 +08:00
`Ctrl-p Ctrl-q` `Ctrl-c`
### 使 `docker port` Error: No public port '80' published for xxx
2017-11-24 00:29:51 +08:00
2016-12-10 17:00:25 +08:00
2017-11-24 00:29:51 +08:00
* `Dockerfile` `EXPOSE`
2016-12-10 17:00:25 +08:00
* `PublishAllPort = true`
###
2017-11-24 00:29:51 +08:00
2019-01-06 09:50:03 +08:00
`supervisord` https://docs.docker.com/config/containers/multi-service_container/ 。
2016-12-10 17:00:25 +08:00
### CPU
2017-11-24 00:29:51 +08:00
2016-12-10 17:00:25 +08:00
使 `docker create` 使 `docker run` 使 -c|--cpu-shares[=0] 使 CPU 使 -m|--memory[=MEMORY] 使
##
2017-11-24 00:29:51 +08:00
2016-12-10 17:00:25 +08:00
### RepositoryRegistryIndex
2017-11-24 00:29:51 +08:00
2016-12-10 17:00:25 +08:00
##
2017-11-24 00:29:51 +08:00
### Docker
2016-12-10 17:00:25 +08:00
2019-04-29 09:26:29 +08:00
使 `systemd` Ubuntu 16.04Centos `/etc/docker/daemon.json`
2016-12-10 17:00:25 +08:00
### Docker
2017-11-24 00:29:51 +08:00
2018-12-13 18:57:41 +08:00
Docker `/var/lib/docker` Docker 使 Linux daemon `-g` `/etc/docker/daemon.json` "data-root" 使 `docker system info | grep "Root Dir"` 使
2016-12-10 17:00:25 +08:00
/storage/docker
```sh
[root@s26 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 50G 5.3G 42G 12% /
tmpfs 48G 228K 48G 1% /dev/shm
/dev/sda1 485M 40M 420M 9% /boot
/dev/mapper/VolGroup-lv_home 222G 188M 210G 1% /home
/dev/sdb2 2.7T 323G 2.3T 13% /storage
[root@s26 ~]# service docker stop
[root@s26 ~]# cd /var/lib/
[root@s26 lib]# mv docker /storage/
[root@s26 lib]# ln -s /storage/docker/ docker
[root@s26 lib]# ls -la docker
lrwxrwxrwx. 1 root root 15 11 17 13:43 docker -> /storage/docker
[root@s26 lib]# service docker start
```
2018-12-13 18:57:41 +08:00
### 使 swap "WARNING: Your kernel does not support cgroup swap limit. WARNING: Your kernel does not support swap limit capabilities. Limitation discarded."
2017-11-24 00:29:51 +08:00
2016-12-10 17:00:25 +08:00
swap 使
2017-11-24 00:29:51 +08:00
* `/etc/default/grub` Ubuntu `GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"`
* grub`$ sudo update-grub`
2016-12-10 17:00:25 +08:00
*
## Docker
### Docker LXCLinux Container
2017-11-24 00:29:51 +08:00
2016-12-10 17:00:25 +08:00
LXC Linux Docker
*
* OverlayFS 便
2016-12-10 17:00:25 +08:00
* Git便
*
* Docker Docker PaaSCI Docker 便
### Docker Vagrant
2017-11-24 00:29:51 +08:00
2016-12-10 17:00:25 +08:00
* Vagrant Boot2Docker Docker Vagrant WindowsMac Linux Docker
* Docker Linux
Vagrant Docker
### Docker Vagrant
2017-11-24 00:29:51 +08:00
Docker Linux Vagrant
2016-12-10 17:00:25 +08:00
使 Linux 使 Docker
2017-11-24 00:29:51 +08:00
使 macOS Windows Vagrant Vagrant 使 Docker
2016-12-10 17:00:25 +08:00
##
2017-11-24 00:29:51 +08:00
### Docker Linux Windows macOS
2017-11-24 09:56:30 +08:00
[ Docker](../../install/)
2017-11-24 00:29:51 +08:00
### 宿 Docker 宿
2016-12-10 17:00:25 +08:00
Docker Docker 宿宿
### Docker
2017-11-24 00:29:51 +08:00
2016-12-10 17:00:25 +08:00
Docker 宿 `/var/run/netns` 宿访
2017-11-24 00:29:51 +08:00
使 1234
2016-12-10 17:00:25 +08:00
2017-11-24 00:29:51 +08:00
```bash
2016-12-10 17:00:25 +08:00
$ docker inspect --format='{{. State.Pid}} ' $container_id
1234
```
2017-11-24 00:29:51 +08:00
`/proc` `/var/run/netns`
```bash
2016-12-10 17:00:25 +08:00
$ sudo ln -s /proc/1234/ns/net /var/run/netns/
```
宿
2017-11-24 00:29:51 +08:00
```bash
2016-12-10 17:00:25 +08:00
$ sudo ip netns show
1234
```
IP `172.17.0.100/16`
2017-11-24 00:29:51 +08:00
```bash
2016-12-10 17:00:25 +08:00
$ sudo ip netns exec 1234 ifconfig eth0 172.17.0.100/16
```
2016-12-10 17:06:04 +08:00
### veth
2017-11-24 00:29:51 +08:00
2016-12-10 17:06:04 +08:00
Docker veth veth
`ip a` `205` 1 `206` `ip a` `206` veth