✍️
Notes.md
  • Table of contents
  • React.Js
    • React Hooks
    • Old :- React : Using Classes
  • Blockchain
    • Solidity
    • Custom ERC20 token
    • Contract
  • Tools and Tech
    • Docker
    • Git version Control
  • Java
    • Data & Data Types
    • IO in Java
    • Data Structures
      • Array in Java
      • Collections in Java
      • Map in Java
      • Enums in Java
      • Linked List in Java
      • List in Java
      • Queues & Stacks
      • Set in Java
      • TreeSet and TreeMap
    • Object Oriented Programming
      • Object Class Methods and Constructor
      • Immutable Class & Objects
      • Constructors
      • Visibility
      • Generics
    • Threads in Java
    • Useful Stuff Java
      • Lambda & Stream
    • Keywords in Java
      • Annotations
      • Comparators
      • Packages in Java
    • Miscellaneous
    • Articles to refer to
  • Golang
    • Competitive Programming in Go
    • Testing simple web server
    • Learning Go : Part 1
    • Maps vs slices
    • Golang Garbage Collector 101
    • Things Golang do differently
    • Go Things
  • Linux
    • Shell programming
    • Linux Commands Part 1 - 4
    • Linux Commands Part 5 - 8
    • Linux Commands Part 9 - 10
  • Software Design
    • Solid Design
    • OOPS
    • Design Patterns
      • Creational Design Pattern
        • Builder DP
        • Factory DP
        • Singleton DP
      • Adapter DP
      • Bridge DP
      • Iterator DP
      • State DP
      • Strategy DP
      • Behavioral Design Pattern
        • Observer DP
      • Structural Design Pattern
        • Facade DP
  • Cloud
    • Google Cloud Platform
      • GCP Core Infrastructure
      • Cloud Networking
  • Spring Boot
    • Spring Basics
      • Spring Beans
      • Important Annotations
      • Important Spring Things
      • Maven Things
      • Spring A.O.P
    • Spring Boot Controller
      • Response Entity Exception Handling
    • Spring Things
    • Spring MVC
    • Spring Data
      • Redis
      • Spring Data JPA
      • JDBC
    • Apache Camel
  • Miscellaneous
    • Troubleshooting and Debugging
Powered by GitBook
On this page
  • Docker basic commands
  • Networking in Docker
  • Embedded DNS

Was this helpful?

  1. Tools and Tech

Docker

PreviousTools and TechNextGit version Control

Last updated 1 year ago

Was this helpful?

Image naming structure : remote_location/username/image_name | ex : docker.io/nginx/nginx

Docker basic commands

  • remove container

    • docker rm -vf $(docker ps -a -q)

  • remove all images

    • docker rmi -f $(docker images -a -q)

  • runs the container from image, gets it from the docker hub

  • if not found locally

    • docker run [image]

  • to list info of containers, -a for more

    • docker ps [-a]

  • stop running container

    • docker stop [container]

  • remove container

    • docker rm [container]

  • list all images

    • docker images

  • remove the image, note all container running of this image

  • should be removed first

    • docker rmi [image name]

  • to download image from remote, not run it immediately

    • docker pull

  • docker stop is no process is running, sleep will delay the stop process`

    • docker run [container] sleep 5

  • to execute a process inside a docker container

    • docker exec [container] [command to run]

  • to run the docker in de-attach mode, that means it will be in put in background

    • docker run -d [container]

  • to attach to the output of the container

    • docker attach [container]

    • docker run [container]:[version]

  • to interact with the terminal of the container, only input

    • docker run -i [container]

  • to interact with the terminal of the container, both input and output

    • docker run -it [container]

  • to attach you system's port to the port open inside the container

    • docker run -p 80:5000 [container]

  • create new volume

    • docker volume create data_volume

  • to save persistent data on disk for it to not get deleted in case the container is deleted

    • path to directory on your system : ex : /opt/datadir

    • path to directory on the container : ex : /var/lib/mysql

docker run -v \
  [path to directory on your system]:[path to directory on the container] \
 [container]

docker run -v [volume name]:[path to directory on the container] [container]

# or

docker run \
	--mount type=bind,source=[volume],target=[volume insider container] \
	[container name]
  • to get info about a container in JSON format

    • docker inspect [container]

  • to get logging info

    • docker logs [container]

  • to specify environment variable when running a container

    • docker run -e [ENV_KEY]=[ENV_VALUE] [container]

Steps to create your own images

Create a file name Dockerfile

  • specify OS

  • update the packages of OS

  • install dependency using apt

  • install python dependencies using pip

  • copy source code into the image

  • start the process

This instructions take place in layered architecture, changes made to one layer will only effect the same layer in the next build

To get all info about build : docker history [image]

#  to build the image
docker build Dockerfile -t [tag name]

# to save img to remote
docker push [tag name]

Sample Dockerfile

FROM [os]

RUN [some command]

COPY [code]

ENTYRPOINT [instruction to start the process]

Networking in Docker

There are 3 network in docker

  • Bridge : network within the docker host, for inter-container communication

  • Host : network to expose the containers to the OS

  • None : specify --network=none

You can find bridge network info for a given container using inspect command

To create custom bridge ( user defined network )

docker network create \\
	--driver bridge \\
	--subnet[subnet]/16 
	[bridge network name]

# to list all network
docker network ls

Embedded DNS

Docker host contains a internal DNS resolver for different containers to communicate to each other. In place of URL, just add the name of the container you want to communicate to.