Docker Cheat Sheet
Background
Docker筆記 - Docker基礎教學 Docker筆記 - 進入Container,建立並操作 PostgreSQL Container Docker筆記 - 更改Container的Configuration Docker筆記 - 讓資料遠離Container,使用 Volume、Bind Mount 與 Tmpfs Mount Docker Docker Compose與Dockerfile差別 Docker Compose 指令
Command
-
Know docker container name
$ docker ps # Then you'll find the container name at the end of the result
-
Go into container bash shell
$ docker exec -it <container_name> bash # 以root的身份進入container # 極度建議以此方法進入bash $ docker exec -u root -it <container_id> /bin/bash
- Check Log
1
$ docker-compose logs
- 啟動所有的 Docker Container 指令如下
1
$ docker-compose up -d
- 停止 docker-compose 執行的所有 Container
1
$ docker-compose stop
- 刪除 docker-compose 的所有 Container
1
$ docker-compose rm
- Leave Container
exit or ctrl-D
- 利用Dockerfile build一個Images並且實際跑起來
1
$ docker run -it --rm $(docker build -q .) /bin/sh
:::spoiler 實作
1
2
3
4
5
6
7
8
9
10
11
12
13$ docker pull httpd # with the latest version $ docker images # check the current images status REPOSITORY TAG IMAGE ID CREATED SIZE httpd latest 75a48b16cd56 4 days ago 168MB $ docker create --name test -p 8080:80 httpd # create a container with the name test and port number is 80 70fd43b63fa04c0daebd8128eff7ec58de26cb5c4c7bf63c0cf30fd03d07f1ab $ docker start 70fd43b63fa0 # start the container 70fd43b63fa0 $ docker ps -a # check container status CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 70fd43b63fa0 httpd "httpd-foreground" 2 minutes ago Up 27 seconds 0.0.0.0:8080->80/tcp test $ docker exec -it test bash # get into container with bash shell as terminal root@70fd43b63fa0:/usr/local/apache2#
:::
Reference
Day 24:使用 Docker-Compose 啟動多個 Docker Container 設定php.ini 【Day 3】 - Docker 基本指令操作
PADNS Midterm Reference
使用 docker 架設 wordpress 網站 ubuntu安装nginx报错:Failed to start A high performance web server and a reverse proxy server
執行步驟
- Destroy Droplet
- Use the new password to login(be send by Digital Ocean)
And then change your password.
- Follow the note to install requirement application
1
2
3
4
5
6
7
8
9
10
11
12$ apt-get update $ apt-get install ca-certificates curl gnupg lsb-release $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg $ echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null $ apt-get update $ apt-get install docker-ce docker-ce-cli containerd.io $ docker run hello-world $ curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose $ chmod +x /usr/local/bin/docker-compose $ docker-compose --version
- Deploy docker
1
$ docker-compose up -d
- 外網掛域名
1
2
3
4
5$ apt install nginx -y $ vim /etc/nginx/sites-enabled/website $ vim docker-compose.yml # add hostname: test.fei.works $ service nginx restart
:::danger It can not set https :::