|
| 1 | +# Intro to Docker |
| 2 | +### Unit: 1 Containers |
| 3 | +CLI Monitoring |
| 4 | + |
| 5 | + |
| 6 | +- |
| 7 | + |
| 8 | +### What’s going on in Containers: |
| 9 | +● docker container top - process list in one container |
| 10 | +● docker container inspect - details of one container config |
| 11 | +● docker container stats - performance stats for all containers |
| 12 | + |
| 13 | + |
| 14 | +- |
| 15 | + |
| 16 | +### Let’s start a nginx container |
| 17 | +● docker container run -d --name nginx nginx |
| 18 | +● docker container top nginx |
| 19 | + |
| 20 | + |
| 21 | +- |
| 22 | + |
| 23 | +### Let’s start a mysql container |
| 24 | +● docker container run -d --name mysql -e MYSQL_RANDOM_ROOT_PASSWORD=true mysql |
| 25 | +● docker container top mysql |
| 26 | + |
| 27 | + |
| 28 | +- |
| 29 | + |
| 30 | +### Docker container inspect |
| 31 | +● docker container inspect mysql |
| 32 | +● This will return a JSON array of all the data involved in starting up the |
| 33 | +container |
| 34 | + |
| 35 | + |
| 36 | +- |
| 37 | + |
| 38 | +### Docker container stats |
| 39 | +● docker container stats |
| 40 | +● This will give you a running play on the processes running in containers on |
| 41 | +your machine |
| 42 | +● This is not what you would use in production |
| 43 | +● It’s great for when you are working on your local machine |
| 44 | + |
| 45 | + |
| 46 | +- |
| 47 | + |
| 48 | +### Getting a Shell inside Containers |
| 49 | +● docker container run -it |
| 50 | +○ starts new containers interactively |
| 51 | +● docker container exec -it |
| 52 | +○ run additional command in existing container |
| 53 | +● Different Linux distros in containers |
| 54 | + |
| 55 | + |
| 56 | +- |
| 57 | + |
| 58 | +### Container flags `-i` , `-t` or `-it` |
| 59 | +● -t pseudo-tty |
| 60 | +○ Simulates a real terminal, like what SSH does |
| 61 | +● -i, --interactive |
| 62 | +○ Keep STDIN open even if not attached |
| 63 | +○ This allows us to keep the session open even when there are no commands |
| 64 | + |
| 65 | + |
| 66 | +- |
| 67 | + |
| 68 | +### Container additional commands |
| 69 | +● usage : docker container run [OPTIONS] IMAGE [COMMAND] [ARGS...] |
| 70 | + ● docker container run -it --name proxy nginx bash |
| 71 | +○ Here by placing bash after the image name ‘nginx’ we are overriding the default action of |
| 72 | +this container |
| 73 | +○ This will log you in as the root user of the container |
| 74 | +○ Try using ls |
| 75 | +○ Using the exit command to leave the container and end. |
| 76 | +○ Containers only run as log as the command on startup |
| 77 | + |
| 78 | + |
| 79 | +- |
| 80 | + |
| 81 | +### Let’s pull down a full distribution |
| 82 | +● docker container run -it --name ubuntu ubuntu |
| 83 | +○ Once logged in run apt-get update |
| 84 | +○ This is a stripped down version of Ubuntu , and would not contain all the things that comes |
| 85 | +with a full distribution by default. |
| 86 | +○ You can even install things normally apt-get install -y curl |
| 87 | +○ Once you exit the container again... it will stop the container |
| 88 | +○ If we restarted the container CURL would be installed |
| 89 | + |
| 90 | + |
| 91 | +- |
| 92 | + |
| 93 | +### Docker container start |
| 94 | +● docker container start --help |
| 95 | +● -a, --attach :: Attach STDOUT/STDERR and forward signals |
| 96 | +● docker container start -ai ubuntu |
| 97 | + |
| 98 | + Docker container exec |
| 99 | +● Let's say we want to look inside of an container already running a process |
| 100 | +● docker container exec -it mysql bash |
| 101 | +○ Will place you in a container inside of sql |
| 102 | +○ In this shell we can jump directly into the mysql command line |
| 103 | +○ Try ps aux |
| 104 | +○ When you finally exit the process will continue |
| 105 | +○ run docker ps |
| 106 | + |
| 107 | + |
| 108 | +- |
| 109 | + |
| 110 | +### Linux Alpine |
| 111 | +● A small security focused distribution of linux |
| 112 | +● Lets pull down a copy of alpine and take a look |
| 113 | +○ docker pull alpine |
| 114 | +○ docker image ls |
| 115 | +● Let’s try : |
| 116 | +○ docker container run -it alpine bash |
| 117 | +○ The above will not work because bash is not part of the distribution |
| 118 | +● Lets try: |
| 119 | +○ docker container run -alpine sh |
| 120 | +○ The above will work because sh is include in this image, although it has less features |
| 121 | +available than bash. |
| 122 | + |
| 123 | + |
| 124 | +- |
| 125 | + |
| 126 | +# Unit: 1 Containers |
| 127 | +### Networking Concepts |
| 128 | + |
| 129 | + |
| 130 | +- |
| 131 | + |
| 132 | +### Docker Networks: Concepts |
| 133 | +● Review of docker container run -p |
| 134 | +● For local dev/testing, networks usually “just work” |
| 135 | +○ Dockers motto Batteries are included but removable |
| 136 | +● Quick porr check with docker container port <container> |
| 137 | +● Learn concepts of Docker Networking |
| 138 | + |
| 139 | + |
| 140 | +- |
| 141 | + |
| 142 | +### Docker Network Defaults |
| 143 | +● Each container connected to a private virtual network “bridge” ○ This is the default docker system network |
| 144 | +● Each virtual network routes through NAT firewall on host IP |
| 145 | +○ The docker daemon configures the host ip address on its default interface so that |
| 146 | +containers can get out to the internet |
| 147 | +● All containers on a virtual network can talk to each other with -p |
| 148 | +● Best practice is to create a new virtual network for each app |
| 149 | +○ Network “zcw_web_app” for mysql and php/apache containers |
| 150 | +○ Network “zcw_api” for mongo and nodejs containers |
| 151 | + |
| 152 | + |
| 153 | +- |
| 154 | + |
| 155 | +### Docker Networks Cont. |
| 156 | +● “Batteries Included, But Removable” |
| 157 | +○ Default work well in many cases, but easy to swap out parts to customize it |
| 158 | +● Things you can change |
| 159 | +○ Make new virtual networks |
| 160 | +○ Attach containers to more than one virtual network (or none) |
| 161 | +○ Skip virtual networks and use host IP (--net=host) |
| 162 | +■ You lose contanerization benefits but it’s unavoidable ○ Use different Docker network drivers to gain new abilities |
| 163 | + |
| 164 | + |
| 165 | +- |
| 166 | + |
| 167 | +### `-p (--publish)` |
| 168 | +● Publishing ports is always in HOST:CONTAINER format |
| 169 | +● RUN: docker container run -p 80:80 --name webhost -d nginx |
| 170 | +● RUN: docker container port webhost |
| 171 | +○ 80/tcp -> 0.0.0.0:80 |
| 172 | + |
| 173 | + |
| 174 | +- |
| 175 | + |
| 176 | +### Inspect `--format` |
| 177 | +● docker container inspect --format '{{ .NetworkSettings.IPAddress }}' webhost ○ Will return the ip address of the container ‘172.17.0.3’ |
| 178 | +● Run: ifconfig en0 |
| 179 | +○ Will return the ip address of local machine ‘10.0.0.92’ |
| 180 | +○ Notice that the two machines are not on the same network |
| 181 | +○ There is an edge firewall that blocks calls in and out |
| 182 | +○ Docker has a default bridge that maps to our local ethernet interface |
| 183 | +○ Using the -p on docker will allow external traffic into the docker virtual network |
| 184 | +○ Containers on the same network have access to each other, unless you use -p there will be |
| 185 | +no incoming calls. |
| 186 | + |
| 187 | + |
| 188 | +- |
| 189 | + |
| 190 | +### Docker Networks: Concepts recap |
| 191 | +● Review of docker container run -p |
| 192 | +● For local/dev testing, networks usually “just work” |
| 193 | +● Quick port check with docker container port <container> |
| 194 | +● Learn concepts of Docker networking |
| 195 | + |
| 196 | + |
| 197 | +- |
| 198 | + |
| 199 | +# Unit: 1 Containers |
| 200 | +### CLI Management |
| 201 | + |
| 202 | + |
| 203 | +- |
| 204 | + |
| 205 | +### Docker Networks : CLI Management |
| 206 | +● Show networks docker network ls |
| 207 | +● Inspect a network docker network inspect |
| 208 | +● Create a network docker network create --driver |
| 209 | +● Attach a network to a container docker network connect |
| 210 | +● Detach a network from container docker network disconnect |
| 211 | + |
| 212 | + |
| 213 | +- |
| 214 | + |
| 215 | +### Docker Networks |
| 216 | +● Run : docker network ls |
| 217 | +● Run : docker network inspect bridge |
| 218 | +○ Will list the containers that are attached to this network |
| 219 | +● Three default networks |
| 220 | +○ Host network - a special network that skips virtual networks but sacrifices security of a |
| 221 | +container |
| 222 | +○ Bridge network - default network for docker host |
| 223 | +○ None network - it has not attachment |
| 224 | + |
| 225 | + |
| 226 | +- |
| 227 | + |
| 228 | +### Docker Networks |
| 229 | +● Run : docker network create zcw_app_network |
| 230 | +● Run : docker network ls |
| 231 | +○ We can now see our new network with a driver of bridge ■ Bridge is the default network driver |
| 232 | +● Run : docker network create --help |
| 233 | +● Run : docker container run -d --name new_nginx --network zcw_app_network nginx |
| 234 | +● Run : docker network inspect zcw_app_network |
| 235 | + |
| 236 | + |
| 237 | +- |
| 238 | + |
| 239 | +### Docker Networks : |
| 240 | +● Docker network connect |
| 241 | +○ Dynamically creates a NIC (networking interface card) in a container on an existing virtual |
| 242 | +network |
| 243 | +● Run : docker network ls |
| 244 | +● Run : docker network inspect bridge |
| 245 | + |
| 246 | + |
| 247 | +- |
| 248 | + |
| 249 | +### Lab : CLI Testing |
| 250 | +● Use different Linux distro containers to check curl cli tool versions |
| 251 | +● Use two different terminal windows to start bash in both centos:7 and |
| 252 | +ubuntu:14.04, using -it |
| 253 | +● Use the docker container --rm options so you can save cleanup |
| 254 | +● Ensure curl is installed and on latest version for that distro |
| 255 | +○ ubuntu : apt-get update && apt-get install curl |
| 256 | +○ Centos : yum update curl |
| 257 | +● check curl --version |
| 258 | + |
0 commit comments