Skip to content

Instantly share code, notes, and snippets.

@marianabocoi
Last active October 20, 2019 17:37
Show Gist options
  • Save marianabocoi/f9a6772faf18278fd1d2da11e252b1be to your computer and use it in GitHub Desktop.
Save marianabocoi/f9a6772faf18278fd1d2da11e252b1be to your computer and use it in GitHub Desktop.
# This file
j.mp/pink-docker
__________________________________________________________________
# Mac Install
# To install brew run one liner from https://brew.sh
brew cask install docker
# Windows install
# https://docs.docker.com/toolbox/overview/#whats-in-the-box
# unfortunately you have to enable Virtualization in bios
# Linux install
# https://docs.docker.com/install/linux/docker-ce/ubuntu/
__________________________________________________________________
# Hello World
# To check it is installed and running
docker run hello-world
__________________________________________________________________
#run a specific opperating system containers
# more images at https://hub.docker.com
docker run -it --rm ubuntu bin/bash
docker run -it --rm centos bin/bash
docker run -it --rm alpine /bin/ash
# exit container with control+D
# Python
docker run -it --rm python:3.5 bin/bash
#Java
docker run -it --rm java:9 bin/bash
__________________________________________________________________
# List all containers
docker ps -a
# List all images
docker images
__________________________________________________________________
# Bind kittens folder in docker container
mkdir kitten
docker run -it --rm -v $(pwd)/kitten:/kitten python:3.5 bin/bash
# run terminal in existing container
docker ps
docker exec -it <CONTAINER ID> bin/bash
__________________________________________________________________
# Access stopped container
# Start container...
docker run -it python:3.5 bin/bash
# Exit container with control+D
# Because we did not use -rm you can see the stopped container when listing all
docker ps -a
# Start conainer again
docker start <CONTAINER ID>
# Use same command to go into a running container as above
docker exec -it <CONTAINER ID> bin/bash
__________________________________________________________________
# Docker cleanup
# Stop a running container
docker stop <CONTAINER ID>
# Kill a running container
docker kill <CONTAINER ID>
# Delete a stopped container
docker rm <CONTAINER ID>
# Delete a docker image
docker rmi <IMAGE ID>
__________________________________________________________________
# Cleanup everything
# Kill all running containers
docker kill $(docker ps -q)
# Delete all stopped containers (including data-only containers)
docker rm $(docker ps -a -q)
# Delete all 'untagged/dangling' (<none>) images
docker rmi $(docker images -q -f dangling=true)
# Delete ALL images
docker rmi $(docker images -q)
__________________________________________________________________
# Basic Dockerfile content
FROM python
COPY hello.py /hello.py
RUN pip install requests
# hello.py
print("Hello Pink")
# Build with following command in the same directory
__________________________________________________________________
# More under the hood - docker implementation specifics - do not need for just running
# https://medium.freecodecamp.org/demystifying-containers-101-a-deep-dive-into-container-technology-for-beginners-d7b60d8511c1
# Tutorial for dockerising Flask app
# https://runnable.com/docker/python/dockerize-your-flask-application
@knappologi
Copy link

knappologi commented Nov 18, 2018

@blagicaz
Copy link

#Java
docker run -it --rm java:9 bin/bash

@basin-ships
Copy link

Command line help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment