1.修改ubuntu的apt源
1) lsb_release –a
查看Codename
2)
1.备份系统自带源
mv /etc/apt/sources.list /etc/apt/sources.list.bak
2.修改/etc/apt/sources.list文件
vim /etc/apt/sources.list
加入以下内容:
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
3.更新生效
apt-get update
注意要使用root账号
sudo vim /etc/apt/sources.list
2.安装docker
安装必要的一些系统工具
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"
更新并安装 Docker CE
sudo apt-get -y update
sudo apt-get -y install docker-ce
启动 Docker CE
$ sudo systemctl enable docker
$ sudo systemctl start docker
测试 Docker 是否安装正确
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:be0cd392e45be79ffeffa6b05338b98ebb16c87b255f48e297ec7f98e123905c
Status: Downloaded newer image for hello-world:latest
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://cloud.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/
一、配置阿里云docker镜像加速器
#配置加速器地址
root@nulige:~# vi /etc/docker/daemon.json
{
"registry-mirrors": ["https://alzgoonw.mirror.aliyuncs.com"]
}
#重启服务
root@nulige:~# systemctl daemon-reload
root@nulige:~# systemctl restart docker
root@nulige:~# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since 六 2018-07-14 15:57:37 CST; 5s ago
Docs: https://docs.docker.com
Main PID: 20924 (dockerd)
Tasks: 24
Memory: 17.5M
CPU: 335ms
CGroup: /system.slice/docker.service
├─20924 /usr/bin/dockerd -H fd://
└─20931 containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock
7月 14 15:57:36 nulige dockerd[20924]: time="2018-07-14T15:57:36.563943482+08:00" level=info
7月 14 15:57:36 nulige dockerd[20924]: time="2018-07-14T15:57:36.806216247+08:00" level=info
7月 14 15:57:36 nulige dockerd[20924]: time="2018-07-14T15:57:36.939167334+08:00" level=info
7月 14 15:57:36 nulige dockerd[20924]: time="2018-07-14T15:57:36.942417843+08:00" level=warni
7月 14 15:57:36 nulige dockerd[20924]: time="2018-07-14T15:57:36.993952096+08:00" level=warni
7月 14 15:57:36 nulige dockerd[20924]: time="2018-07-14T15:57:36.995672598+08:00" level=warni
7月 14 15:57:36 nulige dockerd[20924]: time="2018-07-14T15:57:36.996020601+08:00" level=info
7月 14 15:57:36 nulige dockerd[20924]: time="2018-07-14T15:57:36.996082156+08:00" level=info
7月 14 15:57:37 nulige dockerd[20924]: time="2018-07-14T15:57:37.012728149+08:00" level=info
7月 14 15:57:37 nulige systemd[1]: Started Docker Application Container Engine.
docker create –name percona –v /data/mysql-data:/var/lib/mysql –p 3306:3306 –e MYSQL_ROOT_PASSWORD=123 percona:5.7.23
docker run -it -name test -d nginx:latest /bin/bash
-d: 后台运行容器,并返回容器ID;
-i: 以交互模式运行容器,通常与 -t 同时使用;
-t: 为容器重新分配一个伪输入终端,通常与 -i 同时使用;
docker的操作
1. docker run –p 8080:8080 tomcat
2.docker run –p 8080:8080 -d tomcat
后台进行操作
3.docker ps
4.关闭容器
docker stop ID
5.docker ps –a
查看所有的container
6. docker start containerID
7.docker rm containerId
8.docker rmi imageId
9.docker rm –f containerId
强制删除正在运行的containerId
10
docker run -p 8080:8080 --name tomcat –d tomcat
守护态运行
11.
docker run --name percona -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123 -d percona:5.7.23
12.
docker run --name percona -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123 -v /data/mysql-data:/var/lib/mysql -d percona:5.7.23
13.老是会报错
docker logs percona
写入错误
chmod 777 /data/mysql
错误消失
14.进入容器进行交互式操作
docker exec -it containerID /bin/bash
进入后
cd /webapps/ROOT
echo hello world > index.jsp