Docker簡介
Docker 項目的目标是實作輕量級的作業系統虛拟化解決方案。Docker 的基礎是 Linux 容器(LXC)等技術。其主要目的是保證一緻的運作環境,以及更快速的傳遞與部署。
Docker鏡像與容器
鏡像:鏡像(Image)就是一堆隻讀層(read-only layer)的統一視角。
容器:容器(container)的定義和鏡像(image)幾乎一模一樣,也是一堆層的統一視角,唯一差別在于容器的最上面那一層是可讀可寫的。容器 = 鏡像 + 可讀層。
鏡像有關指令
搜尋鏡像:docker search 在docker index中搜尋image
下載下傳鏡像:docker pull 從docker registry server 中下拉image
上傳鏡像:docker push NAME[:TAG]
鏡像有關的其它,指令均可以通過 docker image --help 檢視
Commands:
build Build an image from a Dockerfile
history Show the history of an image
import Import the contents from a tarball to create a filesystem image
inspect Display detailed information on one or more images
load Load an image from a tar archive or STDIN
ls List images
prune Remove unused images
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rm Remove one or more images
save Save one or more images to a tar archive (streamed to STDOUT by default)
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
容器有關指令
鏡像有關的其它,指令均可以通過 docker container --help 檢視
Commands:
attach Attach local standard input, output, and error streams to a running container
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
exec Run a command in a running container
export Export a container's filesystem as a tar archive
inspect Display detailed information on one or more containers
kill Kill one or more running containers
logs Fetch the logs of a container
ls List containers
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
prune Remove all stopped containers
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
run Run a command in a new container
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
wait Block until one or more containers stop, then print their exit codes
常用指令
使用鏡像建立容器 docker container run -d -p localport:containerport
重新進入容器指令 docker container exec -it /bin/bash
Dockerfile 建立自定義鏡像
FROM ubuntu:20.04
LABEL description='Flask project for flask'
RUN apt-get update
#RUN apt-get upgrade -y
# Install vim
RUN apt-get install -y vim
# Install pip
RUN apt-get install -y python3-pip
RUN pip3 install flask==1.1.2 -i https://pypi.douban.com/simple/ && pip3 install gunicorn==20.1.0 -i https://pypi.douban.com/simple/
COPY /flask /flask
WORKDIR /flask
# 暴露的容器端口
EXPOSE 7080 7081
# 必須用中括号寫,直接寫啟動語句在執行後會自動關閉容器
#CMD ["python3", "./flasktext.py"]
CMD gunicorn -c gunicorn.conf.py flasktext:app
覺得有幫助的話點個贊吧~
作者:糖烤栗子&