亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

目錄 搜尋
Compose About versions and upgrading (Compose) ASP.NET Core + SQL Server on Linux (Compose) CLI environment variables (Compose) Command-line completion (Compose) Compose(組成) Compose command-line reference(組合命令行參考) Control startup order (Compose) Django and PostgreSQL (Compose) Docker stacks and distributed application bundles (Compose) docker-compose build(docker-compose構(gòu)建) docker-compose bundle docker-compose config docker-compose create docker-compose down docker-compose events docker-compose exec docker-compose help docker-compose images docker-compose kill docker-compose logs docker-compose pause docker-compose port docker-compose ps docker-compose pull docker-compose push docker-compose restart docker-compose rm docker-compose run docker-compose scale docker-compose start docker-compose stop docker-compose top docker-compose unpause docker-compose up Environment file (Compose) Environment variables in Compose Extend services in Compose Frequently asked questions (Compose) Getting started (Compose) Install Compose Link environment variables (deprecated) (Compose) Networking in Compose Overview of Docker Compose Overview of docker-compose CLI Quickstart: Compose and WordPress Rails and PostgreSQL (Compose) Sample apps with Compose Using Compose in production Using Compose with Swarm Engine .NET Core application (Engine) About images, containers, and storage drivers (Engine) Add nodes to the swarm (Engine) Apply custom metadata (Engine) Apply rolling updates (Engine) apt-cacher-ng Best practices for writing Dockerfiles (Engine) Binaries (Engine) Bind container ports to the host (Engine) Breaking changes (Engine) Build your own bridge (Engine) Configure container DNS (Engine) Configure container DNS in user-defined networks (Engine) CouchDB (Engine) Create a base image (Engine) Create a swarm (Engine) Customize the docker0 bridge (Engine) Debian (Engine) Default bridge network Delete the service (Engine) Deploy a service (Engine) Deploy services to a swarm (Engine) Deprecated Engine features Docker container networking (Engine) Docker overview (Engine) Docker run reference (Engine) Dockerfile reference (Engine) Dockerize an application Drain a node (Engine) Engine FAQ (Engine) Fedora (Engine) Get started (Engine) Get started with macvlan network driver (Engine) Get started with multi-host networking (Engine) How nodes work (Engine) How services work (Engine) Image management (Engine) Inspect the service (Engine) Install Docker (Engine) IPv6 with Docker (Engine) Join nodes to a swarm (Engine) Legacy container links (Engine) Lock your swarm (Engine) Manage nodes in a swarm (Engine) Manage sensitive data with Docker secrets (Engine) Manage swarm security with PKI (Engine) Manage swarm service networks (Engine) Migrate to Engine 1.10 Optional Linux post-installation steps (Engine) Overview (Engine) PostgreSQL (Engine) Raft consensus in swarm mode (Engine) Riak (Engine) Run Docker Engine in swarm mode Scale the service (Engine) SDKs (Engine) Select a storage driver (Engine) Set up for the tutorial (Engine) SSHd (Engine) Storage driver overview (Engine) Store service configuration data (Engine) Swarm administration guide (Engine) Swarm mode key concepts (Engine) Swarm mode overlay network security model (Engine) Swarm mode overview (Engine) Understand container communication (Engine) Use multi-stage builds (Engine) Use swarm mode routing mesh (Engine) Use the AUFS storage driver (Engine) Use the Btrfs storage driver (Engine) Use the Device mapper storage driver (Engine) Use the OverlayFS storage driver (Engine) Use the VFS storage driver (Engine) Use the ZFS storage driver (Engine) Engine: Admin Guide Amazon CloudWatch logs logging driver (Engine) Bind mounts (Engine) Collect Docker metrics with Prometheus (Engine) Configuring and running Docker (Engine) Configuring logging drivers (Engine) Control and configure Docker with systemd (Engine) ETW logging driver (Engine) Fluentd logging driver (Engine) Format command and log output (Engine) Google Cloud logging driver (Engine) Graylog Extended Format (GELF) logging driver (Engine) Journald logging driver (Engine) JSON File logging driver (Engine) Keep containers alive during daemon downtime (Engine) Limit a container's resources (Engine) Link via an ambassador container (Engine) Log tags for logging driver (Engine) Logentries logging driver (Engine) PowerShell DSC usage (Engine) Prune unused Docker objects (Engine) Run multiple services in a container (Engine) Runtime metrics (Engine) Splunk logging driver (Engine) Start containers automatically (Engine) Storage overview (Engine) Syslog logging driver (Engine) tmpfs mounts Troubleshoot volume problems (Engine) Use a logging driver plugin (Engine) Using Ansible (Engine) Using Chef (Engine) Using Puppet (Engine) View a container's logs (Engine) Volumes (Engine) Engine: CLI Daemon CLI reference (dockerd) (Engine) docker docker attach docker build docker checkpoint docker checkpoint create docker checkpoint ls docker checkpoint rm docker commit docker config docker config create docker config inspect docker config ls docker config rm docker container docker container attach docker container commit docker container cp docker container create docker container diff docker container exec docker container export docker container inspect docker container kill docker container logs docker container ls docker container pause docker container port docker container prune docker container rename docker container restart docker container rm docker container run docker container start docker container stats docker container stop docker container top docker container unpause docker container update docker container wait docker cp docker create docker deploy docker diff docker events docker exec docker export docker history docker image docker image build docker image history docker image import docker image inspect docker image load docker image ls docker image prune docker image pull docker image push docker image rm docker image save docker image tag docker images docker import docker info docker inspect docker kill docker load docker login docker logout docker logs docker network docker network connect docker network create docker network disconnect docker network inspect docker network ls docker network prune docker network rm docker node docker node demote docker node inspect docker node ls docker node promote docker node ps docker node rm docker node update docker pause docker plugin docker plugin create docker plugin disable docker plugin enable docker plugin inspect docker plugin install docker plugin ls docker plugin push docker plugin rm docker plugin set docker plugin upgrade docker port docker ps docker pull docker push docker rename docker restart docker rm docker rmi docker run docker save docker search docker secret docker secret create docker secret inspect docker secret ls docker secret rm docker service docker service create docker service inspect docker service logs docker service ls docker service ps docker service rm docker service scale docker service update docker stack docker stack deploy docker stack ls docker stack ps docker stack rm docker stack services docker start docker stats docker stop docker swarm docker swarm ca docker swarm init docker swarm join docker swarm join-token docker swarm leave docker swarm unlock docker swarm unlock-key docker swarm update docker system docker system df docker system events docker system info docker system prune docker tag docker top docker unpause docker update docker version docker volume docker volume create docker volume inspect docker volume ls docker volume prune docker volume rm docker wait Use the Docker command line (Engine) Engine: Extend Access authorization plugin (Engine) Docker log driver plugins Docker network driver plugins (Engine) Extending Engine with plugins Managed plugin system (Engine) Plugin configuration (Engine) Plugins API (Engine) Volume plugins (Engine) Engine: Security AppArmor security profiles for Docker (Engine) Automation with content trust (Engine) Content trust in Docker (Engine) Delegations for content trust (Engine) Deploying Notary (Engine) Docker security (Engine) Docker security non-events (Engine) Isolate containers with a user namespace (Engine) Manage keys for content trust (Engine) Play in a content trust sandbox (Engine) Protect the Docker daemon socket (Engine) Seccomp security profiles for Docker (Engine) Secure Engine Use trusted images Using certificates for repository client verification (Engine) Engine: Tutorials Engine tutorials Network containers (Engine) Get Started Part 1: Orientation Part 2: Containers Part 3: Services Part 4: Swarms Part 5: Stacks Part 6: Deploy your app Machine Amazon Web Services (Machine) Digital Ocean (Machine) docker-machine active docker-machine config docker-machine create docker-machine env docker-machine help docker-machine inspect docker-machine ip docker-machine kill docker-machine ls docker-machine provision docker-machine regenerate-certs docker-machine restart docker-machine rm docker-machine scp docker-machine ssh docker-machine start docker-machine status docker-machine stop docker-machine upgrade docker-machine url Driver options and operating system defaults (Machine) Drivers overview (Machine) Exoscale (Machine) Generic (Machine) Get started with a local VM (Machine) Google Compute Engine (Machine) IBM Softlayer (Machine) Install Machine Machine Machine CLI overview Machine command-line completion Machine concepts and help Machine overview Microsoft Azure (Machine) Microsoft Hyper-V (Machine) Migrate from Boot2Docker to Machine OpenStack (Machine) Oracle VirtualBox (Machine) Provision AWS EC2 instances (Machine) Provision Digital Ocean Droplets (Machine) Provision hosts in the cloud (Machine) Rackspace (Machine) VMware Fusion (Machine) VMware vCloud Air (Machine) VMware vSphere (Machine) Notary Client configuration (Notary) Common Server and signer configurations (Notary) Getting started with Notary Notary changelog Notary configuration files Running a Notary service Server configuration (Notary) Signer configuration (Notary) Understand the service architecture (Notary) Use the Notary client
文字

  • 1:概況介紹

  • 2:集裝箱

  • 3:服務(wù)

  • 4:成群

  • 5:堆疊

  • 6:部署應(yīng)用程序

先決條件

  • 安裝Docker版本1.13或更高版本...

  • 閱讀第1部分中的方向。

  • 給您的環(huán)境一個快速測試運行,以確保您已經(jīng)設(shè)置好了:

碼頭經(jīng)營哈羅-世界

導(dǎo)言

現(xiàn)在是開始以Docker方式構(gòu)建應(yīng)用程序的時候了。我們將從這種應(yīng)用程序的層次結(jié)構(gòu)的底部開始,該應(yīng)用程序是一個容器,我們將在此頁面上進行介紹。在這個層次上面是一個服務(wù),它定義了容器在生產(chǎn)中的行為方式,在第3部分中進行了討論。最后,在頂層是堆棧,定義了第5部分中介紹的所有服務(wù)的交互。

  • 堆疊

  • 服務(wù)

  • 集裝箱你在這里

您的新開發(fā)環(huán)境

在過去,如果您要開始編寫Python應(yīng)用程序,您的首要任務(wù)就是將Python運行時安裝到您的計算機上。但是,這就造成了這樣一種情況:為了使應(yīng)用程序按預(yù)期運行,計算機上的環(huán)境必須是這樣的;運行應(yīng)用程序的服務(wù)器也是如此。

使用Docker,您只需獲取一個可移植的Python運行時作為映像,無需安裝。然后,您的構(gòu)建可以將基本Python映像與應(yīng)用程序代碼放在一起,確保應(yīng)用程序、其依賴項和運行時都能一起運行。

這些便攜式圖像是由稱為a的東西定義的Dockerfile

使用Dockerfile

Dockerfile將定義容器內(nèi)環(huán)境中發(fā)生的事情。在這個環(huán)境中,對網(wǎng)絡(luò)接口和磁盤驅(qū)動器等資源的訪問是虛擬化的,這與系統(tǒng)的其他部分是隔離的,因此您必須將端口映射到外部世界,并具體說明要將哪些文件“復(fù)制”到該環(huán)境。但是,在這樣做之后,您可以預(yù)期您的應(yīng)用程序的構(gòu)建是在Dockerfile無論在哪里運行都會表現(xiàn)得完全一樣。

Dockerfile

創(chuàng)建一個空目錄。將目錄(cd)更改為新目錄,創(chuàng)建一個名為的文件Dockerfile,將以下內(nèi)容復(fù)制并粘貼到該文件中并保存。注意解釋新Dockerfile中每條語句的注釋。

# Use an official Python runtime as a parent image
FROM python:2.7-slim

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
ADD . /app

# Install any needed packages specified in requirements.txt
RUN pip install -r requirements.txt

# Make port 80 available to the world outside this container
EXPOSE 80# Define environment variable
ENV NAME World

# Run app.py when the container launches
CMD ["python", "app.py"]

Dockerfile指我們還沒有創(chuàng)建的幾個文件,即app.pyrequirements.txt讓我們創(chuàng)造下一個。

應(yīng)用程序本身

再創(chuàng)建兩個文件,requirements.txtapp.py,并將它們放在同一個文件夾中,Dockerfile這就完成了我們的應(yīng)用程序,正如您所看到的,這個應(yīng)用程序非常簡單。當(dāng)以上Dockerfile被塑造成一幅圖像,app.pyrequirements.txt會因為這個而出現(xiàn)DockerfileADD命令的輸出。app.py可以通過HTTP訪問,這要感謝EXPOSE命令。

requirements.txt

Flask
Redis

app.py

from flask import Flaskfrom redis import Redis, RedisErrorimport osimport socket

# Connect to Redis
redis = Redis(host="redis", db=0, socket_connect_timeout=2, socket_timeout=2)app = Flask(__name__)@app.route("/")def hello():    try:
        visits = redis.incr("counter")
    except RedisError:
        visits = "<i>cannot connect to Redis, counter disabled</i>"

    html = "<h3>Hello {name}!</h3>" \           "<b>Hostname:</b> {hostname}<br/>" \           "<b>Visits:</b> {visits}"    return html.format(name=os.getenv("NAME", "world"), hostname=socket.gethostname(), visits=visits)if __name__ == "__main__":
    app.run(host='0.0.0.0', port=80)

現(xiàn)在我們看到了pip install -r requirements.txt安裝用于Python的Flask和Redis庫,應(yīng)用程序打印環(huán)境變量NAME,以及調(diào)用的輸出socket.gethostname()最后,由于Redis沒有運行%28,我們只安裝了Python庫,而沒有安裝Redis本身的%29,因此我們應(yīng)該期望在這里使用它的嘗試會失敗并產(chǎn)生錯誤消息。

:在容器中檢索容器ID時訪問主機的名稱,這就像正在運行的可執(zhí)行文件的進程ID一樣。

而已!您requirements.txt的系統(tǒng)中不需要Python或其他任何東西,也不會在您的系統(tǒng)上安裝或運行此映像??雌饋砟悴]有真正用Python和Flask建立一個環(huán)境,但是你已經(jīng)擁有了。

構(gòu)建應(yīng)用程序

我們已經(jīng)準(zhǔn)備好構(gòu)建這個應(yīng)用程序了。確保您仍然處于新目錄的頂層。這是什么ls應(yīng)顯示:

$ ls
Dockerfile		app.py			requirements.txt

現(xiàn)在運行Build命令。這將創(chuàng)建一個Docker映像,我們將使用它進行標(biāo)記-t所以它有個友好的名字。

docker build -t friendlyhello .

你的形象在哪里?它在您機器的本地Docker映像注冊表中:

$ docker images

REPOSITORY            TAG                 IMAGE ID
friendlyhello         latest              326387cea398

運行應(yīng)用程序

運行應(yīng)用程序,使用以下方法將機器的端口4000映射到容器的已發(fā)布端口80-p*

docker run -p 4000:80 friendlyhello

您應(yīng)該會看到Python正在為您的應(yīng)用提供服務(wù)的通知http://0.0.0.0:80。但是該消息來自容器內(nèi)部,它不知道你將該容器的端口80映射到4000,從而制作正確的URL http://localhost:4000。

轉(zhuǎn)到Web瀏覽器中的URL,查看網(wǎng)頁上的顯示內(nèi)容,包括“HelloWorld”文本、容器ID和Redis錯誤消息。

您還可以使用curl命令在shell中查看相同的內(nèi)容。

$ curl http://localhost:4000<h3>Hello World!</h3><b>Hostname:</b> 8fc990912a14<br/><b>Visits:</b> <i>cannot connect to Redis, counter disabled</i>

*該端口重新映射為4000:80是為了證明你EXPOSEDockerfile,還有你publish使用docker run -p在后面的步驟中,我們將只將主機上的端口80映射到容器中的端口80,然后使用http://localhost...

命中CTRL+C在你的終點站辭職。

現(xiàn)在讓我們在后臺以分離模式運行該應(yīng)用程序:

docker run -d -p 4000:80 friendlyhello

你得到你的應(yīng)用程序的長容器ID,然后被踢回你的終端。您的容器正在后臺運行。您還可以看到縮寫的容器IDdocker container ls%28并且在運行命令%29時兩者都可以互換工作:

$ docker container ls
CONTAINER ID        IMAGE               COMMAND             CREATED
1fa4ab2cf395        friendlyhello       "python app.py"     28 seconds ago

你會看到的CONTAINER ID匹配正在進行的http://localhost:4000...

現(xiàn)在用docker stop若要結(jié)束該進程,請使用CONTAINER ID,就像這樣:

docker stop 1fa4ab2cf395

分享你的形象

為了演示我們剛剛創(chuàng)建的圖像的可移植性,讓我們上傳構(gòu)建的映像并在其他地方運行它。畢竟,當(dāng)您想要將容器部署到生產(chǎn)中時,您將需要學(xué)習(xí)如何推送到注冊表。

注冊表是存儲庫的集合,存儲庫是圖像的集合--有點像GitHub存儲庫,只是代碼已經(jīng)構(gòu)建。注冊中心上的帳戶可以創(chuàng)建許多存儲庫。大docker默認(rèn)情況下,CLI使用Docker的公共注冊表。

:我們在這里使用Docker的公共注冊表,僅僅是因為它是免費的和預(yù)先配置的,但是有許多公共注冊表可供選擇,您甚至可以使用碼頭受信任登記處...

用您的碼頭ID登錄

如果您沒有碼頭帳戶,請在Cloud.docker.com請記下你的用戶名。

登錄到本地計算機上的Docker公共注冊表。

docker login

標(biāo)記圖像

將本地映像與注冊表上的存儲庫關(guān)聯(lián)的符號是username/repository:tag標(biāo)記是可選的,但建議使用它,因為它是注冊表用于為Docker圖像提供一個版本的機制。為上下文提供存儲庫和標(biāo)記有意義的名稱,如get-started:part1。這將把圖像放在get-started存儲庫并將其標(biāo)記為part1...

現(xiàn)在,把它放在一起標(biāo)記圖像。跑docker tag image使用您的用戶名、存儲庫和標(biāo)簽名,以便圖像將上載到您想要的目的地。該命令的語法是:

docker tag image username/repository:tag

例如:

docker tag friendlyhello john/get-started:part1

跑碼頭形象才能看到你的新標(biāo)記圖像。%28你也可以使用docker image ls.%29

$ docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
friendlyhello            latest              d9e555c53008        3 minutes ago       195MB
john/get-started         part1               d9e555c53008        3 minutes ago       195MB
python                   2.7-slim            1c7128a655f6        5 days ago          183MB...

發(fā)布圖像

將標(biāo)記的圖像上載到存儲庫:

docker push username/repository:tag

一旦完成,這個上傳的結(jié)果是公開的。如果你登錄到碼頭樞紐,您將看到新的圖像,在那里,它的拉命令。

從遠程存儲庫中提取并運行映像

從現(xiàn)在開始,你可以用docker run并使用以下命令在任何機器上運行您的應(yīng)用程序:

docker run -p 4000:80 username/repository:tag

如果映像在機器上本地不可用,Docker將從存儲庫中提取它。

docker image rm <image id>
$ docker run -p 4000:80 john/get-started:part1
Unable to find image 'john/get-started:part1' locally
part1: Pulling from orangesnap/get-started
10a267c67f42: Already exists
f68a39a6a5e4: Already exists
9beaffc0cf19: Already exists
3c1fe835fb6b: Already exists
4c9f1fa8fcb8: Already exists
ee7d8f576a14: Already exists
fbccdcced46e: Already exists
Digest: sha256:0601c866aab2adcc6498200efd0f754037e909e5fd42069adeff72d1e2439068
Status: Downloaded newer image for john/get-started:part1 * Running on http://0.0.0.0:80/ (Press CTRL+C to quit)

*如果不指定:tag這些命令的一部分,標(biāo)記為:latest將在構(gòu)建和運行映像時假設(shè)。Docker將使用沒有指定%28標(biāo)記而運行的映像的最后一個版本,而不一定是最近的映像%29。

不管在哪里docker run執(zhí)行時,它將提取您的圖像以及Python和requirements.txt運行你的代碼。所有這些都是在一個整潔的小包中一起運行的,主機只需要安裝Docker就可以運行它了。

第二部分結(jié)論

這一頁就這么多了。在下一節(jié)中,我們將學(xué)習(xí)如何通過在服務(wù)...

繼續(xù)第3部分

重述和備忘單%28可選%29

這是本頁所涵蓋內(nèi)容的終端記錄*

下面列出了這個頁面中的基本Docker命令,以及一些相關(guān)的命令,如果您想在繼續(xù)之前進行一番探索的話。

docker build -t friendlyname .  # Create image using this directory's Dockerfile
docker run -p 4000:80 friendlyname  # Run "friendlyname" mapping port 4000 to 80docker run -d -p 4000:80 friendlyname         # Same thing, but in detached mode
docker container ls                                # List all running containers
docker container ls -a             # List all containers, even those not running
docker container stop <hash>           # Gracefully stop the specified container
docker container kill <hash>         # Force shutdown of the specified container
docker container rm <hash>        # Remove specified container from this machine
docker container rm $(docker container ls -a -q)         # Remove all containers
docker image ls -a                             # List all images on this machine
docker image rm <image id>            # Remove specified image from this machine
docker image rm $(docker image ls -a -q)   # Remove all images from this machine
docker login             # Log in this CLI session using your Docker credentials
docker tag <image> username/repository:tag  # Tag <image> for upload to registry
docker push username/repository:tag            # Upload tagged image to registry
docker run username/repository:tag                   # Run image from a registry
上一篇: 下一篇: