├── README.md ├── dockercheatsheet1.png ├── dockercheatsheet3.png ├── dockercheatsheet4.png ├── dockercheatsheet5.png ├── dockercheatsheet6.png ├── dockercheatsheet7.png └── dockercheatsheet8.png /README.md: -------------------------------------------------------------------------------- 1 | # The Ultimate Docker Cheatsheets 2 | 3 | Full Dockercheatsheets 4 | ![full](https://github.com/sangam14/dockercheatsheets/blob/master/dockercheatsheet8.png) 5 | 6 | Container Management Commands 7 | ![container_management](https://github.com/sangam14/dockercheatsheets/blob/master/dockercheatsheet1.png) 8 | 9 | Inspecting The Container 10 | ![Inspecting The Container](https://github.com/sangam14/dockercheatsheets/blob/master/dockercheatsheet3.png) 11 | ![Interacting with Container1](https://github.com/sangam14/dockercheatsheets/blob/master/dockercheatsheet4.png) 12 | Image Management Commands 13 | ![image management commands](https://github.com/sangam14/dockercheatsheets/blob/master/dockercheatsheet5.png) 14 | Image Transfer Comnands 15 | ![Image Transfer Comnands](https://github.com/sangam14/dockercheatsheets/blob/master/dockercheatsheet6.png) 16 | Builder Main Commands 17 | ![Builder Main Commands](https://github.com/sangam14/dockercheatsheets/blob/master/dockercheatsheet7.png) 18 | 19 | 20 | 21 | 22 | 23 | # docker CLI 24 | 25 | Manage images 26 | ------------- 27 | 28 | ### `docker build` 29 | 30 | ```yml 31 | docker build [options] . 32 | -t "app/container_name" # name 33 | ``` 34 | 35 | Create an `image` from a Dockerfile. 36 | 37 | 38 | ### `docker run` 39 | 40 | ```yml 41 | docker run [options] IMAGE 42 | # see `docker create` for options 43 | ``` 44 | 45 | Run a command in an `image`. 46 | 47 | Manage containers 48 | ----------------- 49 | 50 | ### `docker create` 51 | 52 | ```yml 53 | docker create [options] IMAGE 54 | -a, --attach # attach stdout/err 55 | -i, --interactive # attach stdin (interactive) 56 | -t, --tty # pseudo-tty 57 | --name NAME # name your image 58 | -p, --publish 5000:5000 # port map 59 | --expose 5432 # expose a port to linked containers 60 | -P, --publish-all # publish all ports 61 | --link container:alias # linking 62 | -v, --volume `pwd`:/app # mount (absolute paths needed) 63 | -e, --env NAME=hello # env vars 64 | ``` 65 | 66 | #### Example 67 | 68 | ``` 69 | $ docker create --name app_redis_1 \ 70 | --expose 6379 \ 71 | redis:3.0.2 72 | ``` 73 | 74 | Create a `container` from an `image`. 75 | 76 | ### `docker exec` 77 | 78 | ```yml 79 | docker exec [options] CONTAINER COMMAND 80 | -d, --detach # run in background 81 | -i, --interactive # stdin 82 | -t, --tty # interactive 83 | ``` 84 | 85 | #### Example 86 | 87 | ``` 88 | $ docker exec app_web_1 tail logs/development.log 89 | $ docker exec -t -i app_web_1 rails c 90 | ``` 91 | 92 | Run commands in a `container`. 93 | 94 | 95 | ### `docker start` 96 | 97 | ```yml 98 | docker start [options] CONTAINER 99 | -a, --attach # attach stdout/err 100 | -i, --interactive # attach stdin 101 | 102 | docker stop [options] CONTAINER 103 | ``` 104 | 105 | Start/stop a `container`. 106 | 107 | 108 | ### `docker ps` 109 | 110 | ``` 111 | $ docker ps 112 | $ docker ps -a 113 | $ docker kill $ID 114 | ``` 115 | 116 | Manage `container`s using ps/kill. 117 | 118 | Images 119 | ------ 120 | 121 | ### `docker images` 122 | 123 | ```sh 124 | $ docker images 125 | REPOSITORY TAG ID 126 | ubuntu 12.10 b750fe78269d 127 | me/myapp latest 7b2431a8d968 128 | ``` 129 | 130 | ```sh 131 | $ docker images -a # also show intermediate 132 | ``` 133 | 134 | Manages `image`s. 135 | 136 | ### `docker rmi` 137 | 138 | ```yml 139 | docker rmi b750fe78269d 140 | ``` 141 | 142 | Deletes `image`s. 143 | 144 | Also see 145 | -------- 146 | 147 | * [Getting Started](http://www.docker.io/gettingstarted/) _(docker.io)_ 148 | 149 | 150 | # Dockerfile 151 | 152 | ### Inheritance 153 | 154 | ```docker 155 | FROM ruby:2.2.2 156 | ``` 157 | 158 | ### Variables 159 | 160 | ```docker 161 | ENV APP_HOME /myapp 162 | RUN mkdir $APP_HOME 163 | ``` 164 | 165 | ### Initialization 166 | 167 | ```docker 168 | RUN bundle install 169 | ``` 170 | 171 | ```docker 172 | WORKDIR /myapp 173 | ``` 174 | 175 | ```docker 176 | VOLUME ["/data"] 177 | # Specification for mount point 178 | ``` 179 | 180 | ```docker 181 | ADD file.xyz /file.xyz 182 | COPY --chown=user:group host_file.xyz /path/container_file.xyz 183 | ``` 184 | 185 | ### Onbuild 186 | 187 | ```docker 188 | ONBUILD RUN bundle install 189 | # when used with another file 190 | ``` 191 | 192 | ### Commands 193 | 194 | ```docker 195 | EXPOSE 5900 196 | CMD ["bundle", "exec", "rails", "server"] 197 | ``` 198 | 199 | ### Entrypoint 200 | 201 | ```docker 202 | ENTRYPOINT ["executable", "param1", "param2"] 203 | ENTRYPOINT command param1 param2 204 | ``` 205 | 206 | Configures a container that will run as an executable. 207 | 208 | ```docker 209 | ENTRYPOINT exec top -b 210 | ``` 211 | 212 | This will use shell processing to substitute shell variables, and will ignore any `CMD` or `docker run` command line arguments. 213 | 214 | ### Metadata 215 | 216 | ```docker 217 | LABEL version="1.0" 218 | ``` 219 | 220 | ```docker 221 | LABEL "com.example.vendor"="ACME Incorporated" 222 | LABEL com.example.label-with-value="foo" 223 | ``` 224 | 225 | ```docker 226 | LABEL description="This text illustrates \ 227 | that label-values can span multiple lines." 228 | ``` 229 | 230 | ## See also 231 | 232 | - 233 | 234 | 235 | # docker-compose 236 | 237 | 238 | ### Basic example 239 | 240 | ```yaml 241 | # docker-compose.yml 242 | version: '2' 243 | 244 | services: 245 | web: 246 | build: . 247 | # build from Dockerfile 248 | context: ./Path 249 | dockerfile: Dockerfile 250 | ports: 251 | - "5000:5000" 252 | volumes: 253 | - .:/code 254 | redis: 255 | image: redis 256 | ``` 257 | 258 | ### Commands 259 | 260 | ```sh 261 | docker-compose start 262 | docker-compose stop 263 | ``` 264 | 265 | ```sh 266 | docker-compose pause 267 | docker-compose unpause 268 | ``` 269 | 270 | ```sh 271 | docker-compose ps 272 | docker-compose up 273 | docker-compose down 274 | ``` 275 | 276 | ## Reference 277 | {: .-three-column} 278 | 279 | ### Building 280 | 281 | ```yaml 282 | web: 283 | # build from Dockerfile 284 | build: . 285 | ``` 286 | 287 | ```yaml 288 | # build from custom Dockerfile 289 | build: 290 | context: ./dir 291 | dockerfile: Dockerfile.dev 292 | ``` 293 | 294 | ```yaml 295 | # build from image 296 | image: ubuntu 297 | image: ubuntu:14.04 298 | image: tutum/influxdb 299 | image: example-registry:4000/postgresql 300 | image: a4bc65fd 301 | ``` 302 | 303 | ### Ports 304 | 305 | ```yaml 306 | ports: 307 | - "3000" 308 | - "8000:80" # guest:host 309 | ``` 310 | 311 | ```yaml 312 | # expose ports to linked services (not to host) 313 | expose: ["3000"] 314 | ``` 315 | 316 | ### Commands 317 | 318 | ```yaml 319 | # command to execute 320 | command: bundle exec thin -p 3000 321 | command: [bundle, exec, thin, -p, 3000] 322 | ``` 323 | 324 | ```yaml 325 | # override the entrypoint 326 | entrypoint: /app/start.sh 327 | entrypoint: [php, -d, vendor/bin/phpunit] 328 | ``` 329 | 330 | ### Environment variables 331 | 332 | ```yaml 333 | # environment vars 334 | environment: 335 | RACK_ENV: development 336 | environment: 337 | - RACK_ENV=development 338 | ``` 339 | 340 | ```yaml 341 | # environment vars from file 342 | env_file: .env 343 | env_file: [.env, .development.env] 344 | ``` 345 | 346 | ### Dependencies 347 | 348 | ```yaml 349 | # makes the `db` service available as the hostname `database` 350 | # (implies depends_on) 351 | links: 352 | - db:database 353 | - redis 354 | ``` 355 | 356 | ```yaml 357 | # make sure `db` is alive before starting 358 | depends_on: 359 | - db 360 | ``` 361 | 362 | ### Other options 363 | 364 | ```yaml 365 | # make this service extend another 366 | extends: 367 | file: common.yml # optional 368 | service: webapp 369 | ``` 370 | 371 | ```yaml 372 | volumes: 373 | - /var/lib/mysql 374 | - ./_data:/var/lib/mysql 375 | ``` 376 | 377 | ## Advanced features 378 | 379 | 380 | ### Labels 381 | 382 | ```yaml 383 | services: 384 | web: 385 | labels: 386 | com.example.description: "Accounting web app" 387 | ``` 388 | 389 | ### DNS servers 390 | 391 | ```yaml 392 | services: 393 | web: 394 | dns: 8.8.8.8 395 | dns: 396 | - 8.8.8.8 397 | - 8.8.4.4 398 | ``` 399 | 400 | ### Devices 401 | 402 | ```yaml 403 | services: 404 | web: 405 | devices: 406 | - "/dev/ttyUSB0:/dev/ttyUSB0" 407 | ``` 408 | 409 | ### External links 410 | 411 | ```yaml 412 | services: 413 | web: 414 | external_links: 415 | - redis_1 416 | - project_db_1:mysql 417 | ``` 418 | 419 | ### Hosts 420 | 421 | ```yaml 422 | services: 423 | web: 424 | extra_hosts: 425 | - "somehost:192.168.1.100" 426 | ``` 427 | 428 | ## Contributor - 429 | 430 | Sangam biradar - smbiradar14@gmail.com - https://discord.kubedaily.live 431 | 432 | 433 | -------------------------------------------------------------------------------- /dockercheatsheet1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangam14/dockercheatsheets/e2205f450ab905bbc15facf3f577c098d0e10c97/dockercheatsheet1.png -------------------------------------------------------------------------------- /dockercheatsheet3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangam14/dockercheatsheets/e2205f450ab905bbc15facf3f577c098d0e10c97/dockercheatsheet3.png -------------------------------------------------------------------------------- /dockercheatsheet4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangam14/dockercheatsheets/e2205f450ab905bbc15facf3f577c098d0e10c97/dockercheatsheet4.png -------------------------------------------------------------------------------- /dockercheatsheet5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangam14/dockercheatsheets/e2205f450ab905bbc15facf3f577c098d0e10c97/dockercheatsheet5.png -------------------------------------------------------------------------------- /dockercheatsheet6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangam14/dockercheatsheets/e2205f450ab905bbc15facf3f577c098d0e10c97/dockercheatsheet6.png -------------------------------------------------------------------------------- /dockercheatsheet7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangam14/dockercheatsheets/e2205f450ab905bbc15facf3f577c098d0e10c97/dockercheatsheet7.png -------------------------------------------------------------------------------- /dockercheatsheet8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sangam14/dockercheatsheets/e2205f450ab905bbc15facf3f577c098d0e10c97/dockercheatsheet8.png --------------------------------------------------------------------------------