Created
August 28, 2018 01:43
-
-
Save gladiatorAsh/94475bed0a59463e9a16991cce12ad5b to your computer and use it in GitHub Desktop.
Basic Docker Commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Docker: Images and Containers: Runtime instance of an image Kitematic | |
| Containers and VMs: On Linux, containers run natively and shares the same kernel as OS. Runs a discrete process and is lightweight. VM runs a separate guest OS with access to resources through a hypervisor. | |
| Containerization because: | |
| 1. Flexible: Most complex apps | |
| 2. Interchangeable: Deployment on the fly | |
| 3. Portable: Build locally, deploy and run anywhere | |
| 4. No installation needed except docker | |
| 5. Lightweight, makes CI/CD seamless. Dependency management becomes seamless. | |
| Basic Docker commands | |
| 1. $ docker pull busybox | |
| 2. docker image ls -a # List all images on this machine | |
| 3. docker container ls # List all running containers | |
| 4. docker run -p 4000:80 friendlyhello # Run "friendlyname" mapping port 4000 to 80 | |
| 5. $ docker ps | |
| 6. docker container ls -a # List all containers, even those not running | |
| 7. docker container stop <hash> # Gracefully stop the specified container | |
| 8. docker container kill <hash> # Force shutdown of the specified container | |
| 9. docker container rm <hash> # Remove specified container from this machine | |
| 10. docker container rm $(docker container ls -a -q) # Remove all containers | |
| 11. $ docker container prune | |
| 12. $ docker image rm <image id> # Remove specified image from this machine | |
| 13. docker image rm $(docker image ls -a -q) # Remove all images from this machine | |
| 14. docker login # Log in this CLI session using your Docker credentials | |
| 15. $ docker stop | |
| 16. docker tag <image> username/repository:tag # Tag <image> for upload to registry | |
| 17. docker push username/repository:tag # Upload tagged image to registry | |
| 18. docker run username/repository:tag # Run image from a registry | |
| 19. docker build -t friendlyhello . # Create image using this directory's Dockerfile | |
| Sample Dockerfile | |
| # Use an official Python runtime as a parent image | |
| FROM python:2.7-slim | |
| # Set the working directory to /app | |
| WORKDIR /app | |
| # Copy the current directory contents into the container at /app | |
| ADD . /app | |
| # Install any needed packages specified in requirements.txt | |
| RUN pip install --trusted-host pypi.python.org -r requirements.txt | |
| # Make port 80 available to the world outside this container | |
| EXPOSE 80 | |
| # Define environment variable | |
| ENV NAME World | |
| # Run app.py when the container launches | |
| CMD ["python", "app.py"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment