Open uniquejava opened 6 years ago
http://www.cnblogs.com/ivictor/p/4834864.html (总结的真好!)
我的经验, 当container中的某个目录比如/data
存在很多文件的时候(APP)
第一次RUN时不要使用-v参数, 使用不带-v参数的RUN命令跑成功后, 将那个/data目录通过docker cp container_name:/data/ /Users/cyper/xx_data
命令拷贝到本地.
然后删除这个container, 最后加上-v /Users/cyper/xx_data:/data
参数重新RUN这个image.
docker exec -it container_id_or_name command
这里的command可以是/bin/bash
, 可以是whoami
, env
等等任意可以在container的terminal中执行的命令。
例: docker exec -it wex1 ls -a /root
见: https://stackoverflow.com/questions/30172605/how-to-get-into-a-docker-container
docker logs -f tomcat1
docker logs --tail 50 --follow --timestamps tomcat1
docker inspect <container id> | grep "IPAddress"
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id
https://stackoverflow.com/questions/17157721/how-to-get-a-docker-containers-ip-address-from-the-host
https://medium.com/@mccode/processes-in-containers-should-not-run-as-root-2feae3f0df3b
docker load < WEX_DAE_AC_V12.0.0_LNX_ML.DockerImage.tar
docker images
docker run --name wex1 -p 8390:8390 -p 8393:8393 -td wex_dae_ac
docker logs wex1
# 文件copy
docker cp wex1:/data /Users/cyper/esadmin/data
# 直接进bash内部
docker exec -it wex1 /bin/bash
docker container rm/start/stop wex1
## docker compose
docker-compose up
docker-compose.yml
```yml
version: '3'
services:
mysqldb:
image: mysql:5.7
container_name: mysqldb
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: admin
MYSQL_DATABASE: catalog
MySQL错误: https://github.com/passbolt/passbolt_docker/issues/103
you have to remove the volumes before changing the mysql versions.
docker-compose rm
docker volume rm list_of_your_volumes
docker-compose up
Install from Docker (Official)
# 删除旧版本
$ yum -y remove docker-common docker container-selinux docker-selinux docker-engine
$ yum -y install wget
$ wget https://download.docker.com/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
$ yum -y install docker-ce
$ systemctl start docker
不用 sudo即可使用docker命令的办法, 将当前用户加入docker组.
Run this command in your favourite shell and then completely log out of your account and log back in (if in doubt, reboot!):
sudo usermod -a -G docker $USER
https://stackoverflow.com/questions/24309526/how-to-change-the-docker-image-installation-directory
https://stackoverflow.com/questions/31747061/creating-a-docker-volume-at-a-specific-location
https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
https://docs.docker.com/develop/develop-images/multistage-build/
## 只用lts版本(偶数版本, 不要用latest TAG)
## 尽量用alpine (少包含很多linux命令, 体积小很多),不要用slim
## Alpine用的apk, slim用的apt作为包管理工具
## Alpine CVE scanning fails?
FROM node:10-alpine
EXPOSE 3000
RUN apk add --update curl
# WORKDIR能自动创建dir并CD, 不要使用RUN mkdir
WORKDIR /usr/src/app
# 不要用ADD (除非你知道为什么要用 -- ADD可以自动下载, 解压, 大多数情况下COPY就够了)
COPY package.json package-lock.json* ./
RUN npm install && npm cache clean --force
COPY . .
CMD [ "node", "./bin/www" ]
设置代理
在~/.docker/daemon.json或/etc/docker/daemon.json 文件并添加上 registry-mirrors 键值然后重启。
Dockerfile
build==>
Imagerun==>
Container清理没有tag的image
According to the docker documentation you can list only untagged (dangling) images with
and redirect them to
docker rmi
command like that:Notice
-q
param thats only show numeric IDs of containers.镜像CRUD操作
文件拷贝 (不用启动container、爽得1p)
实例 将主机/www/runoob目录拷贝到容器96f7f14e99ab的/www目录下。
docker cp /www/runoob 96f7f14e99ab:/www/
将主机/www/runoob目录拷贝到容器96f7f14e99ab中,目录重命名为www。
docker cp /www/runoob 96f7f14e99ab:/www
将容器96f7f14e99ab的/www目录拷贝到主机的/tmp目录中。
docker cp 96f7f14e99ab:/www /tmp/
容器CRUD操作
综合实例, 拉建跑(RHEL MongoDB)
Learn Docker in 12 Minutes Get started with Docker for Mac How to Dockerize a Node.js application
imooc免费课程
src/index.php
Dockerfile (Writing a Dockerfile)
. 命令行登录报错
docker login
Unable to docker login through CLI - unauthorized: incorrect username or password 解决: docker id不要使用email, 用登录docker.com后右上角显示的用户名。docker run --name wex1 -v /Users/cyper/esadmin/data:/data -p 8390:8390 -p 8393:8393 -td wex_dae_ac