이미지 이름에 별도의 태그를 붙이지 않으면 latest 태그가 자동으로 붙어서 최신버전의 이미지를 로컬에서 찾거나 dockerhub에서 내려받는다.
백그라운드로 redis 컨테이너가 실행되고 있는지 ping으로 테스트해보자. 로컬호스트의 1234번 포트와 연결되어 있으므로 포트번호 1234로 테스트한다.
➜ ~ ping localhost -p 1234
PATTERN: 0x1234
PING localhost (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.052 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.101 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.100 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.091 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.094 ms
64 bytes from 127.0.0.1: icmp_seq=5 ttl=64 time=0.094 ms
^C
--- localhost ping statistics ---
6 packets transmitted, 6 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.052/0.089/0.101/0.017 ms
mysql 컨테이너 실행하기
환경변수를 옵션으로 줘서 mysql 컨테이너를 실행해보겠다.
$ docker run -e MYSQL_ALLOW_EMPTY_PASSWORD=true -e MYSQL_DATABASE='daeun-db' -p 3306:3306 mysql
--env, -e
컨테이너에 환경변수를 설정한다.
위 명령어를 실행하면 두 가지 환경변수가 mysql 에 셋팅된다.( root계정으로 로그인 시 비밀번호를 입력을 생략하고 daeun-db 라는 이름의 데이터베이스를 생성한다.) 컨테이너에 들어가서 확인해보자.
➜ ~ docker exec -it f43167e21be6 bash
root@f43167e21be6:/# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.17 MySQL Community Server - GPL
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| daeun-db |
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.01 sec)
mysql>