Skip to content

Instantly share code, notes, and snippets.

@etoxin
Last active September 6, 2017 14:13
Show Gist options
  • Save etoxin/05d9b6986dbd3a849a5b9e28292c401d to your computer and use it in GitHub Desktop.
Save etoxin/05d9b6986dbd3a849a5b9e28292c401d to your computer and use it in GitHub Desktop.
Docker

Basic Docker Cheatsheet

  • docker images Show local images.
  • docker ps -a show started and stopped containers. docker ps List all only running docker containers.
  • docker stop <containerId> Stop a docker container.
  • docker start <containerId> Starts a docker container.
  • Pause and unpause with docker pause and docker unpause
  • docker run Runs a container. eg. docker run ubuntu
  • docker rm Delete a contaner. eg. docker rm <containerId>
  • docker image ls List downloaded docker images.
Enter a contaner

docker exec -it <mycontainer> bash to exit run exit

Building a new docker

-t means tag which is mydockerimage in the example below.

docker build -t mydockerimage .

Running

  • docker run -p 4000:80 mydockerimage Run a docker image on port 4000
  • docker run -it ubuntu bash this is not very useful but it shows you how to start and enter a container.
  • docker run -id ubuntu Run a container and don't make it stop.
Copy a file from a container to a host.

docker cp <containerId>:/file/path/within/container/file.txt /host/path/target/file.txt

Other useful commands

  • docker stats --all shows a running list of containers.

Full guide

https://github.com/wsargent/docker-cheat-sheet

FROM node:boron
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
COPY package.json .
# For npm@5 or later, copy package-lock.json as well
# COPY package.json package-lock.json ./
RUN npm install
# Bundle app source
COPY . .
EXPOSE 8080
CMD [ "npm", "start" ]
FROM kyma/docker-nginx
COPY src/ /var/www
CMD 'nginx'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment