Docker現在已經支持在windows下安裝,不過我用的是阿里雲的ubuntu系統,所以下面的安裝使用都是基於ubuntu系統的,centos也差不多,只不過是用yum來安裝,ubuntu使用apt安裝
安裝
- 登陸自己的linux服務器,設置apt的源
vim /etc/apt/sources.list
設置爲阿里的鏡像源
deb http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic main
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic main
deb http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic-updates main
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic-updates main
deb http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic universe
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic universe
deb http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic-updates universe
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic-updates universe
deb http://mirrors.cloud.aliyuncs.com/ubuntu bionic-security main
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu bionic-security main
deb http://mirrors.cloud.aliyuncs.com/ubuntu bionic-security universe
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu bionic-security universe
- 設置docker鏡像源
vim /etc/apt/sources.list.d/docker.list
deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable
- 更新鏡像源以及安裝依賴軟件
sudo apt-get update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
- 添加祕鑰安裝docker
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-get install docker-ce
- 查看版本
docker version
能顯示說明安裝成功
運行第一個例子
- 拉取鏡像,是從docker官方倉庫拉取,你也可以指定地址如網易的倉庫
docker pull hello-world
- 查看鏡像
docker images
hello-world latest fce289e99eb9 6 months ago 1.84kB
我們可以看到剛纔拉到本地的鏡像
- 啓動鏡像
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應用
docker ps
- 當前運行的容器
docker container ls
和docker ps 一樣
- 運行鏡像,啓動鏡像後悔生成一個容器
docker run 鏡像名:tag #tag 可選
- 停止容器,也指停止docker應用
docker stop 容器id
- 刪除容器
docker rm -f 容器id
- 刪除鏡像,必須先停止使用該鏡像的容器
docker rmi -f 鏡像名:tag
- 從遠程倉庫拉鏡像
docker pull 鏡像名:tag #如果是私有倉庫,需要用戶名密碼驗證。默認官方公共倉庫
- 顯示本地的所有鏡像
docker images
基本有了這些命令,你就可以開始玩docker了,下節課,開始使用docker運行一個簡單的java應用,以及學習docker鏡像的製作。
歡迎關注我的公中號:mike啥都想搞
,一起交流學習