Intro to Docker
Unit: 1 Containers
CLI Monitoring
-
What’s going on in Containers:
● docker container top - process list in one container ● docker container inspect - details of one container config ● docker container stats - performance stats for all containers
-
Let’s start a nginx container
● docker container run -d –name nginx nginx ● docker container top nginx
-
Let’s start a mysql container
● docker container run -d –name mysql -e MYSQL_RANDOM_ROOT_PASSWORD=true mysql ● docker container top mysql
-
Docker container inspect
● docker container inspect mysql ● This will return a JSON array of all the data involved in starting up the container
-
Docker container stats
● docker container stats ● This will give you a running play on the processes running in containers on your machine ● This is not what you would use in production ● It’s great for when you are working on your local machine
-
Getting a Shell inside Containers
● docker container run -it ○ starts new containers interactively ● docker container exec -it ○ run additional command in existing container ● Different Linux distros in containers
-
Container flags -i
, -t
or -it
● -t pseudo-tty ○ Simulates a real terminal, like what SSH does ● -i, –interactive ○ Keep STDIN open even if not attached ○ This allows us to keep the session open even when there are no commands
-
Container additional commands
● usage : docker container run [OPTIONS] IMAGE [COMMAND] [ARGS…] ● docker container run -it –name proxy nginx bash ○ Here by placing bash after the image name ‘nginx’ we are overriding the default action of this container ○ This will log you in as the root user of the container ○ Try using ls ○ Using the exit command to leave the container and end. ○ Containers only run as log as the command on startup
-
Let’s pull down a full distribution
● docker container run -it –name ubuntu ubuntu ○ Once logged in run apt-get update ○ This is a stripped down version of Ubuntu , and would not contain all the things that comes with a full distribution by default. ○ You can even install things normally apt-get install -y curl ○ Once you exit the container again… it will stop the container ○ If we restarted the container CURL would be installed
-
Docker container start
● docker container start –help ● -a, –attach :: Attach STDOUT/STDERR and forward signals ● docker container start -ai ubuntu
Docker container exec ● Let’s say we want to look inside of an container already running a process ● docker container exec -it mysql bash ○ Will place you in a container inside of sql ○ In this shell we can jump directly into the mysql command line ○ Try ps aux ○ When you finally exit the process will continue ○ run docker ps
-
Linux Alpine
● A small security focused distribution of linux ● Lets pull down a copy of alpine and take a look ○ docker pull alpine ○ docker image ls ● Let’s try : ○ docker container run -it alpine bash ○ The above will not work because bash is not part of the distribution ● Lets try: ○ docker container run -alpine sh ○ The above will work because sh is include in this image, although it has less features available than bash.