安装Docker以及Docker-compose
安装Docker以及Docker-compose

安装Docker以及Docker-compose

这篇文章的步骤是

先安装Docker,然后安装Docker-compose,然后再用Docker-compose安装tomact

 

docker安装

docker的安装我们采用apt

先安装一些必要的系统工具

sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common

然后安装GPG证书

curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

然后把软件源信息写进去,这里我们仍然用的阿里云

sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

然后用apt安装docker-ce(ee我们暂时用不着)

sudo apt-get -y update
sudo apt-get -y install docker-ce

 

这里跑完之后docker就算安装完了,然后我们测试一下安装是否成功

先启动docker

sudo systemctl enable docker
sudo systemctl start docker
Ubuntu 14.04 请使用sudo service docker start命令启动

然后测试

docker run hello-world

如果输出以下内容证明安装成功

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

 

 

docker-compose安装

 

这里我们使用pip方式安装(这种方式是将 Compose 当作一个 Python 应用来从 pip 源中安装。)

 

我们首先查看自己的python版本

直接在终端输入python就可以看到版本信息

如果低于3.5

那么我们进入到usr/bin目录

然后执行

sudo rm -rf python
sudo ln -s /usr/bin/python3  /usr/bin/python

然后再看一下python版本,应该已经变成了3.5以上

然后安装docker-compose

sudo pip install -U docker-compose

如果提示

sudo: pip: command not found

那么先执行

sudo apt-get install python3-pip

执行后再安装

sudo pip install -U docker-compose

看到提示

Collecting docker-compose
  Downloading https://files.pythonhosted.org/packages/43/bf/a9fe1f4b6e0f2ceac7eb7e2dab2fd03edd2fd5ffa8cd90d55ba1453af8b7/docker_compose-1.26.2-py2.py3-none-any.whl (139kB)
    100% |████████████████████████████████| 143kB 380kB/s 

如果跑到最后还提示你

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-ngz4zyt8/cryptography/

解决方法是更新 setuptools 和 pip之后再重新安装

pip install --upgrade setuptools

python -m pip install --upgrade pip

最后输出

Successfully installed bcrypt-3.2.0 cached-property-1.5.2 cffi-1.14.6 charset-normalizer-2.0.4 cryptography-3.4.8 distro-1.6.0 docker-5.0.2 docker-compose-1.29.2 dockerpty-0.4.1 docopt-0.6.2 paramiko-2.7.2 pycparser-2.20 pynacl-1.4.0 python-dotenv-0.19.0 requests-2.26.0 texttable-1.6.4 websocket-client-0.59.0

就证明docker-compose安装好了

 

tomact安装

拉取官方的镜像

docker pull tomcat

下载完之后运行容器

docker run --name tomcat -p 8080:8080 -v $PWD/test:/usr/local/tomcat/webapps/test -d tomcat

启动之后看一下运行情况

docker ps

如果运行起来了就用ifconfig查一下自己的IP

然后访问IP:8080看一下有没有页面,如果有,那就可以了

 

5 1 投票
Article Rating
订阅
提醒
0 评论
内联反馈
查看所有评论