(base) MacBook-Pro:~ user$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
169fb3d755a7 httpd "httpd-foreground" 3 minutes ago Up 3 minutes 80/tcp TestApache
(base) MacBook-Pro:~ user$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
(base) MacBook-Pro:~ user$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
169fb3d755a7 httpd "httpd-foreground" 6 minutes ago Exited (0) About a minute ago TestApache
(base) MacBook-Pro:~ user$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
833378a10de6 httpd "httpd-foreground" 3 minutes ago Up 3 minutes 0.0.0.0:8080->80/tcp testapache
(base) MacBook-Pro:~ user$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
131a2f10e6c0 mysql "docker-entrypoint.s…" About a minute ago Up About a minute 3306/tcp, 33060/tcp TestMysql
(base) MacBook-Pro:~ user$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4. イメージの削除
1. イメージ一覧確認
$ docker image ls
実行例
(base) MacBook-Pro:~ user$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 760b7cbba31e 13 days ago 192MB
mysql latest e68e2614955c 5 weeks ago 638MB
httpd latest 50a1bd9b297f 6 weeks ago 194MB
2. コンテナの確認
削除するイメージを利用中のコンテナが存在しないことを確認する
$ docker ps -a
実行例
(base) MacBook-Pro:~ user$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
(base) MacBook-Pro:~ user$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 760b7cbba31e 13 days ago 192MB
mysql latest e68e2614955c 5 weeks ago 638MB
(base) MacBook-Pro:~ user$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu updated 89cce6ac7789 3 years ago 73.9MB
ubuntu latest 1d622ef86b13 3 years ago 73.9MB
(base) MacBook-Pro:~ user$ docker network ls
NETWORK ID NAME DRIVER SCOPE
b220cbd769bb bridge bridge local
1cbeb5a3cb94 host host local
d821c8dd183f none null local
▼作業後
(base) MacBook-Pro:~ user$ docker network ls
NETWORK ID NAME DRIVER SCOPE
b220cbd769bb bridge bridge local
1cbeb5a3cb94 host host local
d821c8dd183f none null local
698727259a46 wpnetwork bridge local
3. MySQLコンテナ作成 / 起動
$ docker run --name コンテナ名 -dit --net=ネットワーク名 -e MYSQL_ROOT_PASSWORD=MySQLのrootパスワード -e MYSQL_DATABASE=データベース領域名 -e MYSQL_USER=MySQLのユーザ名 -e MYSQL_PASSWORD=MySQLのパスワード mysql --character-set-server=文字コード --collation-server=照合順序 --default-authentication-plugin=認証方式
(base) MacBook-Pro:~ user$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
34dc8ec341f9 mysql "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 3306/tcp, 33060/tcp TestMySQL
(base) MacBook-Pro:~ user$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f014cba48f26 wordpress "docker-entrypoint.s…" 5 minutes ago Up 5 minutes 0.0.0.0:8085->80/tcp TestWordPress
34dc8ec341f9 mysql "docker-entrypoint.s…" 12 minutes ago Up 12 minutes 3306/tcp, 33060/tcp TestMySQL
(base) MacBook-Pro:~ user$ docker network ls
NETWORK ID NAME DRIVER SCOPE
b220cbd769bb bridge bridge local
1cbeb5a3cb94 host host local
d821c8dd183f none null local
▼作業後
(base) MacBook-Pro:~ user$ docker network ls
NETWORK ID NAME DRIVER SCOPE
4dcd1af72842 bridge bridge local
1cbeb5a3cb94 host host local
d821c8dd183f none null local
11637b60ace1 rmnetwork bridge local
3. MySQLコンテナ作成 / 起動
$ docker run --name コンテナ名 -dit --net=ネットワーク名 -e MYSQL_ROOT_PASSWORD=MySQLのrootパスワード -e MYSQL_DATABASE=データベース領域名 -e MYSQL_USER=MySQLのユーザ名 -e MYSQL_PASSWORD=MySQLのパスワード mysql --character-set-server=文字コード --collation-server=照合順序 --default-authentication-plugin=認証方式
(base) MacBook-Pro:~ user$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d6d51e90a00f mysql "docker-entrypoint.s…" 19 seconds ago Up 19 seconds 3306/tcp, 33060/tcp TestMySQL
(base) MacBook-Pro:~ user$ docker run --name TestRedmine --network rmnetwork -p 8086:3000 -e REDMINE_DB_MYSQL=TestMySQL -e REDMINE_DB_DATABASE=myrmdb -e READMINE_DB_USERNAME=myuser -e REDMINE_DB_PASSWORD=mysqlpass redmine
Unable to find image 'redmine:latest' locally
latest: Pulling from library/redmine
f546e941f15b: Already exists
d9a1158a666a: Pull complete
368d332d7b2f: Pull complete
da45132b6189: Pull complete
285d25921a70: Pull complete
bd2a81dc6d62: Pull complete
08cfc026dddd: Pull complete
3c880fe82001: Pull complete
cc1a5a526112: Pull complete
8ad5393fa962: Pull complete
5d2228618116: Pull complete
193434ade290: Pull complete
cd78565a97ba: Pull complete
Digest: sha256:098c88729c37cec76dad76088f682931304ba6f6080df3857475abe7e23859b8
Status: Downloaded newer image for redmine:latest
Your Gemfile lists the gem puma (>= 0) more than once.
You should probably keep only one of them.
Remove any duplicate entries and specify the gem only once.
While it's not a problem now, it could cause errors if you change the version of one of them later.
The Gemfile's dependencies are satisfied
rake aborted!
ActiveRecord::ConnectionNotEstablished: Access denied for user 'root'@'172.18.0.3' (using password: YES) (ActiveRecord::ConnectionNotEstablished)
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/connection_adapters/mysql2_adapter.rb:45:in `rescue in new_client'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/connection_adapters/mysql2_adapter.rb:39:in `new_client'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/connection_adapters/mysql2_adapter.rb:23:in `mysql2_connection'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `public_send'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `new_connection'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:926:in `checkout_new_connection'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:905:in `try_to_checkout_new_connection'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:866:in `acquire_connection'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:588:in `checkout'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:428:in `connection'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:1128:in `retrieve_connection'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/connection_handling.rb:327:in `retrieve_connection'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/connection_handling.rb:283:in `connection'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/tasks/database_tasks.rb:237:in `migrate'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/railties/databases.rake:92:in `block (3 levels) in <top (required)>'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/railties/databases.rake:90:in `each'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/railties/databases.rake:90:in `block (2 levels) in <top (required)>'
/usr/local/bundle/gems/rake-13.1.0/exe/rake:27:in `<top (required)>'
Caused by:
Mysql2::Error::ConnectionError: Access denied for user 'root'@'172.18.0.3' (using password: YES) (Mysql2::Error::ConnectionError)
/usr/local/bundle/gems/mysql2-0.5.6/lib/mysql2/client.rb:97:in `connect'
/usr/local/bundle/gems/mysql2-0.5.6/lib/mysql2/client.rb:97:in `initialize'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/connection_adapters/mysql2_adapter.rb:40:in `new'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/connection_adapters/mysql2_adapter.rb:40:in `new_client'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/connection_adapters/mysql2_adapter.rb:23:in `mysql2_connection'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `public_send'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `new_connection'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:926:in `checkout_new_connection'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:905:in `try_to_checkout_new_connection'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:866:in `acquire_connection'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:588:in `checkout'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:428:in `connection'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:1128:in `retrieve_connection'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/connection_handling.rb:327:in `retrieve_connection'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/connection_handling.rb:283:in `connection'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/tasks/database_tasks.rb:237:in `migrate'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/railties/databases.rake:92:in `block (3 levels) in <top (required)>'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/railties/databases.rake:90:in `each'
/usr/local/bundle/gems/activerecord-6.1.7.6/lib/active_record/railties/databases.rake:90:in `block (2 levels) in <top (required)>'
/usr/local/bundle/gems/rake-13.1.0/exe/rake:27:in `<top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
6. コンテナのステータス確認
$ docker ps
実行例
(base) MacBook-Pro:~ user$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5124d728f516 redmine "/docker-entrypoint.…" 2 minutes ago Up 2 minutes 0.0.0.0:8086->3000/tcp TestRedmine
d6d51e90a00f mysql "docker-entrypoint.s…" 29 minutes ago Up 29 minutes 3306/tcp, 33060/tcp TestMySQL
(base) MacBook-Pro:~ user$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
testapache_image latest 4a3015092ac2 27 seconds ago 194MB
httpd latest 50a1bd9b297f 6 weeks ago 194MB
7. 作成したイメージからのコンテナ作成/起動
$ docker run --name コンテナ名 -d -p ホスト側ポート:コンテナ側ポート 作成したイメージ名