I don’t think I am too different to most people where when you don’t use something regularly enough you tend to forget it. One of the big reasons for creating this blog was so that I could note down commands and snippets that I don’t use enough to remember but still need to reference it enough to note it down.
Currently I am using Docker Compose for my daily use so all my commands are conveniently in a YAML file. Earlier today I was working on upgrading my MySQL container to the latest version… super basic entry level commands and stuff that I feel i should instantly know but just don’t do it enough to remember the exact command. These are my goto commands that i need … I’ll probably update this post as I need to add more.
Login to Docker Hub
$ docker login -e <email> -p <password> -u <user>
Build Docker
# Pull & build from url $ docker build <url> # Pull & build from docker hub tag $ docker build <name:tag> # Build from local file system and set tag $ docker build -t <name:tag> ./
Run Docker
$ docker run <name:tag> # My most used options -d Run in detached mode -i Interactive mode -v <hostPath:containerPath> Link volume -p <hostPort:containerPort> Set ports -e <variable=value> Set environment variables --name <containerName> $ docker run -p <hostPort:containerPort> -v <hostPath:containerPath> <name:tag>
Push Docker to Docker Hub
$ docker push <name:tag>
Manage Containers
# View running containers & get running container id's $ docker ps -a # View docker images $ docker images # Stop Container $ docker stop <containerId> # Remove container $ docker rm <containerId> $ docker rmi <image> # Remove all containers & images $ docker rm $(docker ps -a -q) $ docker rmi $(docker images -q)
Docker Compose
# Build docker containers $ docker-compose build # Start containers $ docker-compose up # Shutdown containers $ docker-compose down # Reset containers $ docker-compose rm