Docker 基礎環境安裝
2 1 月, 2023
JR最近開始複習Docker使用,早期Docker剛出來的時候JR就搶先學習,不過當時的時空背景,很多服務都還是跑在VMware虛擬機上,公司方面也比較守舊,因此JR只能自己下設的伺服器玩,Docker經過多年的雲端運用驗證,許多公司也陸續由傳統虛擬機的使用方式轉換使用Docker,而現在也有不少協同管理Docker的工具平台,因此JR決定將放下許久的Docker重拾起來,第一步就是安裝Docker。
JR使用的環境為Ubuntu Server,以下以此系統為基礎來安裝Docker。
Docker安裝
sudo apt-get install docker.io -y
查看Docker版本
sudo docker --version
執行結果:
Docker version 20.10.2, build 20.10.2-0ubuntu1~20.04.2
開啟Docker服務
設定開機自動啟動:
sudo systemctl enable docker
啟動Docker服務:
sudo systemctl start docker
測試
先來載個image做測試。
sudo docker pull hello-world
查看images。
sudo docker images
執行結果:
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest d1165f221234 3 months ago 13.3kB
執行image。
sudo 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/
看到以上結果即為成功。