Skip to content

nikhil36/docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Docker commands

Simple commands to get started with docker


1. Launching containers


  1. Run a container
    docker run <image>
  2. Run conatiner and drop to shell
    docker run -it <image>
    Full form
    docker run --interactive --tty <image>
  3. Run a container in background
    docker run -d <image>
  4. Set container restart settings
    docker run --restart (always|no|on-failure[:maxretries]|unless-stopped) <image>
  5. Start an exited container
    docker start <name>
  6. Remove a container when exited
    docker run -rm <image>
  7. Provide container nickname
    docker run --name <name> <image>

2. Accessing containers


  1. Run commands inside a contaner
    docker exec <name> <command>
    e.g. docker exec test_container ps-aux
  2. Log into a shell inside a container to run more complex commands
    docker exec -it <container_name> <shell_name>
    Example for running bash shell:
    docker exec -it test-container bash
  3. Copying file from the container
    docker cp <container_name>:<path> <to_path>
    Example for copying nginx config from a container:
    docker cp default.config nginx-container:/etc/nginx/conf.d/default.conf .

3. Container management


  1. Stop container
    docker stop <name>
    e.g. docker stop test_container
  2. Remove container
    docker rm <name>
    e.g. docker rm test_container
  3. Remove all stopped containers
    docker container prune
  4. Rename a container
    docker rename <old_name> <new_name>
  5. Get stats for container like CPU info etc
    docker stats <container_name>
  6. Get detailed info about a container like public ip adress etc
    docker inspect <container_name>
  7. Save container as an image to used later on
    docker commit <container_name> <image_name>
  8. Important command to map container port to host server
    docker run -p <host_port>:<container_port> <container_image>

4. Image management


  1. Pull remote image
    docker pull <image-name>
    e.g. docker pull alpine
  2. Show all images pulled already
    docker image ls
  3. Remove image
    docker image rm <image-name>
  4. Remove problematic images
    docker image prune
  5. Remove images not linked to a container
    docker image rm <image-name>
  6. View image information
    docker image inspect <image-name>

5. Pushing image to docker hub


  1. Log in to your Docker account on the CLI.
    docker login --username=<username>
  2. Tag the image with the repo name.
    docker tag <image> <username>/<reponame>
  3. Push the image to Docker Hub.
    docker push <username>/<reponame>

About

Docker

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors