Docker-compose 2
在 [docker-compose 1] 已經完成安裝compose及執行一個container
現在來測試一次跑多組containers
首先,編譯第一個container所需執行的程式 [Connect to mysql from golang]
更改 main()
1 | func main() { |
go build -o goSql goSql.go
再來,編譯第二個container所需執行的程式
更改
1 | func main() { |
go build -o goSql_2 goSql.go
更改 docker-compose.yml
build:
container_name: jeff
image: centos
ports:
- 9080:9080
volumes:
- /home/jeff/code/:/home/code
restart: always
stdin_open: true
tty: true
command: bash -c "/home/code/goSql"
build_2:
container_name: jeff_2
image: centos
ports:
- 9081:9080
volumes:
- /home/jeff/code/:/home/code
restart: always
stdin_open: true
tty: true
command: bash -c "/home/code/goSql_2"
執行
docker-compose up -d
Check…
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
80ac6694738f centos “bash -c /home/code/g" About a minute ago Up 58 seconds 0.0.0.0:9081->9080/tcp jeff_2
a6cb9b81c8e6 centos “bash -c /home/code/g" 4 minutes ago Up 57 seconds 0.0.0.0:9080->9080/tcp jeff
再確認兩筆資料表有寫入資料庫