docker鐨勯暅鍍忎笌瀹瑰櫒

dk 鐨勬灦鏋勫拰搴曞眰鎶鏈

docker platform

docker engine

docker architecture

client

docker build
docker pull
docker run

docker_host

docker daemon
containers
images

registry

搴曞眰鎶鏈敮鎸

瀹為獙鐜浠嬬粛

docker image

浠涔堟槸image

sudo docker image ls

image鐨勮幏鍙

鍘绘帀docker鐨剆udo

sudo docker version
sudo groupadd docker
sudo gpasswd -a vagrant docker
sudo service docker restart
exit
vagrant ssh
docker version

鍐欎竴涓畝鍗曠殑base image

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

浠涔堟槸container

docker container ls
docker container ls -a(閫鍑虹殑涔熻兘鐪嬪埌)
more hello-world/Dockerfile
docker run ubuntu

浜や簰寮忚繍琛

docker run -it ubuntu

docker 鐨勫懡浠

docker management commends

commands

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)

鏋勫缓docker闀滃儚

绗1绉嶆柟娉

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

浣嗘槸涓嶆彁鍊$敤杩欑鏂规硶鍒涘缓闀滃儚,涓嶅畨鍏

绗2绉嶆柟娉

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"

闀滃儚鐨勫彂甯
– docker hub
鍏堝湪docker Hub涓婃敞鍐屼竴涓处鍙
docker login
docker push nirolee/hello-world:latest

鎷夊彇
docker pull nirolee/hello-world

run a local registry :quick version

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

All posts

Other pages


Deprecated: 鏂囦欢 娌℃湁 comments.php 鐨勪富棰 鑷増鏈 3.0.0 璧峰凡寮冪敤锛屼笖娌℃湁鍙敤鐨勬浛浠c 璇峰湪鎮ㄧ殑涓婚涓寘鍚竴涓 comments.php 妯℃澘銆 in /www/wwwroot/liguoqi.site/wp-includes/functions.php on line 6078

鍙戣〃鍥炲

鎮ㄧ殑鐢靛瓙閭鍦板潃涓嶄細琚叕寮銆 蹇呭~椤瑰凡鐢 * 鏍囨敞