前提:亚马逊云已经配置好启动。

安全组入站策略如下:

云服务器使用docker搭建服务_docker

出站策略如下:

云服务器使用docker搭建服务_工具_02

登陆EC2后,默认只能用ec2-user用户登陆,然后切换到root:

sudo su

用yum执行安装docker提示No package docker avaible

yum install docker -y

云服务器使用docker搭建服务_公众号_03

解决方法:

在/etc/yum.repos.d/下加CentOS7-Base-163.repo文件:

vi CentOS7-Base-163.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base - 163.com
baseurl=http://mirrors.163.com/centos/7/os/x86_64
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates - 163.com
baseurl=http://mirrors.163.com/centos/7/updates/x86_64
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - 163.com
baseurl=http://mirrors.163.com/centos/7/extras/x86_64
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - 163.com
baseurl=http://mirrors.163.com/centos/7/centosplus/x86_64
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

保存退出后,执行命令:

yum makecache

然后执行yum安装docker命令:

yum install docker -y

安装完后如下图:

云服务器使用docker搭建服务_centos_04

启动docker:

## 启动 docker 服务
systemctl start docker
chkconfig docker on

查看docker版本:

docker version

云服务器使用docker搭建服务_centos_05

拉取 docker 镜像:

好了,现在让我们直接拉取别人做好的 docker 镜像。这里选择的是 github上的 shadowsock vpn docker 镜像,直接执行以下命令:

docker pull oddrationale/docker-shadowsocks

云服务器使用docker搭建服务_docker_06

运行 docker 镜像:

运行如下命令启动该 docker 镜像。

docker run -d -p 8001:8001 oddrationale/docker-shadowsocks -s 0.0.0.0 -p 8001 -k yourpassword-m aes-256-cfb

云服务器使用docker搭建服务_centos_07

运行docker ps -a查看容器是否已成功运行起来了。

docker ps -a

云服务器使用docker搭建服务_工具_08

linux上curl命令调:

curl -k localhost:8001

云服务器使用docker搭建服务_工具_09

windows上curl命令调:

云服务器使用docker搭建服务_docker_10

回显如上说明已经部署好了,接下来你要干什么就是你的事了…



作者简洁


作者:小碗汤,一位热爱、认真写作的小伙,目前维护原创公众号:『我的小碗汤』,专注于写golang、docker、kubernetes等知识等提升硬实力的文章,期待你的关注。  作者:小碗汤)