Debug Commands
AsafsMacBook:~ aahmadov$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b7421b65d01a redis:4.0 "docker-entrypoint.s…" 6 minutes ago Up 6 minutes 6379/tcp quizzical_wilson
9e0452128f10 redis:latest "docker-entrypoint.s…" 6 minutes ago Up 6 minutes 6379/tcp strange_jones
Fetch the logs of a container
AsafsMacBook:~ aahmadov$ docker logs b7421b65d01a
1:C 28 May 14:04:15.360 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 28 May 14:04:15.360 # Redis version=4.0.14, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 28 May 14:04:15.360 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
1:M 28 May 14:04:15.361 * Running mode=standalone, port=6379.
1:M 28 May 14:04:15.362 # Server initialized
1:M 28 May 14:04:15.362 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
1:M 28 May 14:04:15.362 * Ready to accept connections
Assign a name to the container
AsafsMacBook:~ aahmadov$ docker run -d -p6000:6060 --name redis-old redis:4.0
cdcf56d4b7ba38b56f382e0ad6421cf72e267025a1a485d371ec8f97f7c49039
AsafsMacBook:~ aahmadov$ docker logs redis-old
1:C 28 May 15:20:06.472 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 28 May 15:20:06.472 # Redis version=4.0.14, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 28 May 15:20:06.473 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
1:M 28 May 15:20:06.473 * Running mode=standalone, port=6379.
1:M 28 May 15:20:06.474 # Server initialized
1:M 28 May 15:20:06.474 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
1:M 28 May 15:20:06.474 * Ready to accept connections
Run a command in a running container
AsafsMacBook:~ aahmadov$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cdcf56d4b7ba redis:4.0 "docker-entrypoint.s…" 11 minutes ago Up 11 minutes 6379/tcp, 0.0.0.0:6000->6060/tcp redis-old
b7421b65d01a redis:4.0 "docker-entrypoint.s…" About an hour ago Up About an hour 6379/tcp quizzical_wilson
9e0452128f10 redis:latest "docker-entrypoint.s…" About an hour ago Up About an hour 6379/tcp strange_jones
AsafsMacBook:~ aahmadov$ docker exec -it cdcf56d4b7ba /bin/bash
root@cdcf56d4b7ba:/data# pwd
/data
root@cdcf56d4b7ba:/data# whoami
root
root@cdcf56d4b7ba:/data#
Ports in Docker
▪ Multiple containers can run on your host machine
Problem:
▪ Your laptop has only certain ports available
▪ Conflict when same port on host machine, so we need to map to a free port on host machine:
Last updated