docker build
docker pull
docker run
docker daemon
containers
images
sudo docker image ls
more Dockerfile
docker build -t official/redis:latest
docker pull ubuntu:14.04
sudo docker version
sudo groupadd docker
sudo gpasswd -a vagrant docker
sudo service docker restart
exit
vagrant ssh
docker version
docker image ls
docker pull hello-world
sudo yum install vim gcc git glibc locate glibc-static
vim hello.c
#include<stdio.h>
int main()
{
printf("hello docker\n");
}
gcc -static hello.c -o hello
vim Dockerfile
FROM scratch
ADD hello /
CMD ["/hello"]
docker build -t nirolee/hello-world
docker container ls
docker container ls -a
(閫鍑虹殑涔熻兘鐪嬪埌)
more hello-world/Dockerfile
docker run ubuntu
docker run -it ubuntu
docker container rm CONTAINER ID
(ID 涓嶇敤鍐欏叏 鑳藉尯鍒嗗氨琛) 缂╁啓 docker rm id
docker container ls -a
缂╁啓 docker ps -a
docker image ls
缂╁啓docker images
docker image rm id
缂╁啓 docker rmi id
docker container ls -a | awk {'print$1'} 缂╁啓 docker container ls -aq
鍏ㄩ儴娓呯悊
docker rm $(docker container ls -aq)
娓呯悊閫鍑虹殑container
docker rm $(docker container ls -f "status=exited" -q)
create a new image from a container’s changes
docker container commit
渚嬪
docker images
docker run -it centos
yum install -y vim
exit
docker container ls -a
docker commit [options] container [repository[:tag]] [flags]
docker commit elegant_mestorf nirolee/centos-vim
浣嗘槸涓嶆彁鍊$敤杩欑鏂规硶鍒涘缓闀滃儚,涓嶅畨鍏
build an image from a dockerfile
docker image build
渚嬪
mkdir docker-centos-vim
cd docker-centos-vim
vim Dockerfile
FROM centos
RUN yum install -y vim
docker build -t nirolee/centos-vim-new .
Dockerfile 璇硶
– FROM
+ FROM scratch # 鍒朵綔base image 浠庡ご鍒朵綔鐨勬剰鎬
+ FROM centos # 浣跨敤base image
+ FROM ubuntu:14.04
灏介噺鐢ㄥ畼鏂圭殑image
– LABEL
+ LABEL maintainer = “nirolee@foxmail.com”
+ LABEL version=”1.0″
+ LABEL description=”this is description”
metadata涓嶅彲灏
– RUN
+ RUN yum update && yum install -y vim
\python-dev
+ apt-get update && apt-get install -y perl \
pwgen –no-install-recommends && rm -rf \
/var/lib/apt/lists/* #娉ㄦ剰娓呯悊cache
+ /bin/bash -c ‘source’ $HOME/.bashrc; echo $HOME’
鎵ц鍛戒护骞跺垱寤烘柊鐨刬mage layer
澶嶆潅run鐢ㄥ弽鏂滅嚎鎹㈣,閬垮厤鏃犵敤鍒嗗眰,鍚堝苟澶氭潯鍛戒护鎴愪竴琛
– WORKDIR
+ WORKDIR /root
+ WORKDIR /test # 濡傛灉娌℃湁浼氳嚜鍔ㄥ垱寤簍est鐩綍
+ WORKDIR demo
+ RUN pwd #杈撳嚭缁撴灉搴旇鏄 /test/demo
鐢╓ORKDIR锛屼笉瑕佺敤RUN cd,灏介噺鐢ㄧ粷瀵圭洰褰
– ADD and COPY
+ ADD hello /
+ ADD test.tar.gz / #娣诲姞鍒版牴鐩綍骞惰В鍘
+ WORKON /root
ADD hello test # /root/test/hello
+ WORKON /root
COPY hello test/
澶ч儴鍒嗘儏鍐,COPY浼樹簬ADD add闄や簡COPY杩樻湁瑙e帇鍔熻兘 娣诲姞杩滅▼鏂囦欢/鐩綍鐢╟url鎴杦get
璁剧疆瀹瑰櫒鍚姩鏃惰繍琛岀殑鍛戒护
Shell 鍜 Exec鏍煎紡
– Shell鏍煎紡
RUN apt-get install -y vim
CMD echo "hello docker"
ENTRYPOINT echo "hello docker"
RUN ["apt-get", "install", "-y", "vim"]
CMD ["/bin/echo", "hello docker"]
ENTRYPOINT ["/bin/echo", "hello docker"]
闀滃儚鐨勫彂甯
– docker hub
鍏堝湪docker Hub涓婃敞鍐屼竴涓处鍙
docker login
docker push nirolee/hello-world:latest
鎷夊彇
docker pull nirolee/hello-world
docker run -d -p 5000:5000 --restart always --name registry registry:2
sudo ls /etc/docker
sudo more /etc/docker/daemon.json
{“insecure-registries”: [“192.168.0.1:5000”]}
sudo vim /lib/systemd/system/docker.service
docker push 192.168.0.1:5000/hello-world
鏌ョ湅鏄惁push鎴愬姛
GET /v2/_catalog
鍙戣〃鍥炲