Ubuntu中怎么安装和应用Docker Compose(docker compose,ubuntu,开发技术)

时间:2024-05-07 00:27:46 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

Docker Compose是一个用来定义和运行复杂应用的Docker工具。一个使用Docker容器的应用,通常由多个容器组成。使用Docker Compose不再需要使用shell脚本来启动容器。

Ubuntu中怎么安装和应用Docker Compose

安装 Docker

我们需要安装 Docker 来安装 Docker Compose。首先为官方 Docker 仓库添加公钥。

$curl-fsSLhttps://download.docker.com/linux/ubuntu/gpg|sudoapt-keyadd-

接下来,添加 Docker 仓库到 apt 源列表:

$sudoadd-apt-repository"deb[arch=amd64]https://download.docker.com/linux/ubuntu$(lsb_release-cs)stable"

更新包数据库,并使用 apt 安装 Docker

$sudoapt-getupdate$sudoaptinstalldocker-ce

在安装进程结束后,Docker 守护程序应该已经启动并设为开机自动启动。我们可以通过下面的命令来查看它的状态:

$sudosystemctlstatusdocker---------------------------------●docker.service-DockerApplicationContainerEngineLoaded:loaded(/lib/systemd/system/docker.service;enabled;vendorpreset:enabled)Active:active(running)

安装 Docker Compose

现在可以安装 Docker Compose 了。通过执行以下命令下载当前版本。

#curl-Lhttps://github.com/docker/compose/releases/download/1.14.0/docker-compose-`uname-s`-`uname-m`>/usr/local/bin/docker-compose

为二进制文件添加执行权限:

#chmod+x/usr/local/bin/docker-compose

检查 Docker Compose 版本:

$docker-compose-v

输出应该如下:

docker-composeversion1.14.0,buildc7bdf9e

测试 Docker Compose

Docker Hub 包含了一个用于演示的 Hello World 镜像,可以用来说明使用 Docker Compose 来运行一个容器所需的配置。

创建并打开一个目录:

$mkdirhello-world$cdhello-world

创建一个新的 YAML 文件:

$$EDITORdocker-compose.yml

在文件中粘贴如下内容:

unixmen-compose-test:image:hello-world

注意: 第一行是容器名称的一部分。 保存并退出。

运行容器

接下来,在 hello-world 目录执行以下命令:

$sudodocker-composeup

如果一切正常,Compose 输出应该如下:

Pullingunixmen-compose-test(hello-world:latest)...latest:Pullingfromlibrary/hello-worldb04784fba78d:PullcompleteDigest:sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74fStatus:Downloadednewerimageforhello-world:latestCreatinghelloworld_unixmen-compose-test_1...Creatinghelloworld_unixmen-compose-test_1...doneAttachingtohelloworld_unixmen-compose-test_1unixmen-compose-test_1|unixmen-compose-test_1|HellofromDocker!unixmen-compose-test_1|Thismessageshowsthatyourinstallationappearstobeworkingcorrectly.unixmen-compose-test_1|unixmen-compose-test_1|Togeneratethismessage,Dockertookthefollowingsteps:unixmen-compose-test_1|1\.TheDockerclientcontactedtheDockerdaemon.unixmen-compose-test_1|2\.TheDockerdaemonpulledthe"hello-world"imagefromtheDockerHub.unixmen-compose-test_1|3\.TheDockerdaemoncreatedanewcontainerfromthatimagewhichrunstheunixmen-compose-test_1|executablethatproducestheoutputyouarecurrentlyreading.unixmen-compose-test_1|4\.TheDockerdaemonstreamedthatoutputtotheDockerclient,whichsentitunixmen-compose-test_1|toyourterminal.unixmen-compose-test_1|unixmen-compose-test_1|Totrysomethingmoreambitious,youcanrunanUbuntucontainerwith:unixmen-compose-test_1|$dockerrun-itubuntubashunixmen-compose-test_1|unixmen-compose-test_1|Shareimages,automateworkflows,andmorewithafreeDockerID:unixmen-compose-test_1|https://cloud.docker.com/unixmen-compose-test_1|unixmen-compose-test_1|Formoreexamplesandideas,visit:unixmen-compose-test_1|https://docs.docker.com/engine/userguide/unixmen-compose-test_1|helloworld_unixmen-compose-test_1exitedwithcode0Docker

容器只能在命令(LCTT 译注:此处应为容器中的命令)还处于活动状态时运行,因此当测试完成运行时,容器将停止运行。

 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:Ubuntu中怎么安装和应用Docker Compose的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:Ubuntu怎么安装Swift编程语言下一篇:

3 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18