{"id":22173843,"url":"https://github.com/puneethkumarck/docker-command-tips","last_synced_at":"2026-01-05T17:05:01.443Z","repository":{"id":129140313,"uuid":"122097189","full_name":"Puneethkumarck/docker-command-tips","owner":"Puneethkumarck","description":"This repo contains useful docker commands for java developers in development","archived":false,"fork":false,"pushed_at":"2018-03-19T18:02:02.000Z","size":50,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-29T22:46:11.739Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Puneethkumarck.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-19T17:31:34.000Z","updated_at":"2018-03-19T18:02:03.000Z","dependencies_parsed_at":"2023-05-15T01:45:46.779Z","dependency_job_id":null,"html_url":"https://github.com/Puneethkumarck/docker-command-tips","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Puneethkumarck%2Fdocker-command-tips","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Puneethkumarck%2Fdocker-command-tips/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Puneethkumarck%2Fdocker-command-tips/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Puneethkumarck%2Fdocker-command-tips/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Puneethkumarck","download_url":"https://codeload.github.com/Puneethkumarck/docker-command-tips/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245325223,"owners_count":20596818,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-02T07:35:47.469Z","updated_at":"2026-01-05T17:04:56.408Z","avatar_url":"https://github.com/Puneethkumarck.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# docker-command-tips\nThis repo contains useful docker commands for java developers in development\n\n```\ndocker -v ( displays docker version installed on the machine)\ndocker info ( docker information Os verison , kernal version etc)\ndocker COMMAND --help \ndocker image ls (list docker images)\ndocker container ls (list docker contaniers)\ndocker contanier run --help\n\n```\n\nRun docker container\n===================\n\n```\ndocker container run cassandra:latest\n===\u003e cassandra:latest here refers to cassandra is the image name available in docker hub registry and latest refers to version of the        cassandra image .\n\ndocker container run -it cassandra:latest\n===\u003e  start the container interactive mode (-it refers to interactive)\n      ctrl c kills the container in interactive mode.\n\ndocker container run -d cassandra:latest \n===\u003e run the container in background\n\ndocker container stop container_id \n===\u003e get the container id by running docker container ls / docker conatiner ls -a command\n\ndocker conatiner rm container_id \n===\u003e (it removes the container from docker host)\n\ndocker container run -d --name my_cassandra cassandra:latest \n===\u003e Naming the conatiner using --name parameter\n\ndocker container rm -f container_id \n===\u003e which will stop and remove the container using single command\n\ndocker container run -it jboss/wildfly bash \n===\u003e starting bash shell in wildfly -bash command overrides running container)\n\n```\n\nRun Container ports /volumes\n===========================\n\n```\nExpose ports \u0026 attach volume\ndocker container run -d --name my_cassandra -P cassandra:latest\n===\u003e run the container using -P command which will choose random port to be accessible by localhost\n\ndocker container logs my_assandra \n===\u003e to check the container logs\n\ndocker container run -d --name my_cassandra -p 9042:9042 cassandra:latest \n===\u003e -p 9042:9042 which makes cassandra accessible in 9042 in localhost\n\ndocker container run -d -name my_cassnadra -p 9042:9042 -v /temp/logs:bin/logs cassandra:latest\n===\u003e here -v option to mount the volume from cassandra container to local disk\n\n```\n\ndocker images\n=============\n```\nFROM -\u003e its used to refer base image .\nCMD -\u003e cmd which needs to be executed in dockerimage.\ndocker image --help\ndocker image build -t \u003cimagename\u003e . --\u003e to build docker image .(dot) refers context current directory.\ndocker history \u003cimage_name\u003e --\u003e to check history of the docker image   \n```\n\ndocker image instruction command\n================================\n```\nCOPY --\u003e Copy new files / directories in to container file system.\n\nADD --\u003e Allows tar file auto extraction in image ADD app.tar.gz  /opt/var/myapp .\n   Can download files from remote url\n\nRUN : used for installing software package\n     ex: RUN apt-get update \u0026\u0026 apt-get install -y git\n         RUN /opt/jboss/wildfly/bin/add-user.sh admin Admin#007 -silent\n\nCMD : defaults for executing container;can be overriden from CLI\n      CMD [\"/opt/jboss/wildfly/bin/standalone.sh\", \"-b\", \"0.0.0.0\" , \"-bmanagement\" , \"0.0.0.0\"]\n      docker run wildfly bash\n      \nENTRYPOINT : configures the container executable;can be overriden using --entrypoint from CLI\n              Default value : /bin/sh -c\n              \nEXPOSE : network ports on which the container is listening\n\nVOLUME :creates a mount point with the specified name\n\nUSER : sets the user name or UID to use when running the image\n\nHEALTH CHECK : performs a healthcheck on the application inside the container\n\nHEALTHCHECK --interval=5s --timeout=3s CMD curl --fail http://localhost:8091/pools || exit 1\n\n******************\nSample docker image:   \nFROM openjdk:jdk-alpine\nCOPY helloworldApp/target/helloworldApp.jar /deployments/\nCMD java -jar /deployments/helloworldApp.jar\n*******************\n\n```\n\nTAG Image\n=========\n```\nIf u build the image without specifying the tag it will be defaultly tagged as latest\ndocker image build .\n\nBelow command builds image with tagged as 1\ndocker image build -t myapp:1\n\nBelow command builds image with tagged as latest\ndocker image build -t myapp:latest\n\nassiging the image to latest\ndocker image tag myapp:1 myapp:latest\n\ndocker run container myapp\n\npushing image to docker hub:\ndocker image tag myapp:1 puneethkumarck/myapp:latest\ndocker login\nusername:***************\npassword:***************\n\ndocker push puneethkumarck/myapp:latest\n\nLocal registry:\ndocker run -d -p 5000:5000 --restart always --name registry registry:2.6.0\ndocker image tag myapp:1 localhost:5000/puneethkumarck/myapp:latest\ndocker image push localhost:5000/puneethkumarck/myapp:latest\n\n```\n\nDocker Compose\n==============\n\n - define and run multi container applications\n - configuration defined in one or more files\n    - docker-compose.yaml (default file name)\n    - docker-compose.override.yml (default)\n    - multiple files specified using -f option\n- single command to up and running/destroy all the application containers \n    - docker compose up\n    - docker compose down\n    \n- docker-compose commands\n\n```\nbuild              Build or rebuild services\n  bundle             Generate a Docker bundle from the Compose file\n  config             Validate and view the Compose file\n  create             Create services\n  down               Stop and remove containers, networks, images, and volumes\n  events             Receive real time events from containers\n  exec               Execute a command in a running container\n  help               Get help on a command\n  images             List images\n  kill               Kill containers\n  logs               View output from containers\n  pause              Pause services\n  port               Print the public port for a port binding\n  ps                 List containers\n  pull               Pull service images\n  push               Push service images\n  restart            Restart services\n  rm                 Remove stopped containers\n  run                Run a one-off command\n  scale              Set number of containers for a service\n  start              Start services\n  stop               Stop services\n  top                Display the running processes\n  unpause            Unpause services\n  up                 Create and start containers\n  version            Show the Docker-Compose version information\n```\n\n- docker compose up options\n\n```\n-d                         Detached mode: Run containers in the background,\n                               print new container names. Incompatible with\n                               --abort-on-container-exit and --timeout.\n    --no-color                 Produce monochrome output.\n    --no-deps                  Don't start linked services.\n    --force-recreate           Recreate containers even if their configuration\n                               and image haven't changed.\n                               Incompatible with --no-recreate.\n    --no-recreate              If containers already exist, don't recreate them.\n                               Incompatible with --force-recreate.\n    --no-build                 Don't build an image, even if it's missing.\n    --no-start                 Don't start the services after creating them.\n    --build                    Build images before starting containers.\n    --abort-on-container-exit  Stops all containers if any container was stopped.\n                               Incompatible with -d.\n    -t, --timeout TIMEOUT      Use this timeout in seconds for container shutdown\n                               when attached or when containers are already.\n                               Incompatible with -d.\n                               running. (default: 10)\n    --remove-orphans           Remove containers for services not\n                               defined in the Compose file\n    --exit-code-from SERVICE   Return the exit code of the selected service container.\n                               Implies --abort-on-container-exit.\n    --scale SERVICE=NUM        Scale SERVICE to NUM instances. Overrides the `scale`\n                               setting in the Compose file if present.\n\n```\n\n- docker compose down options\n\n```\n      --rmi type              Remove images. Type must be one of:\n                              'all': Remove all images used by any service.\n                              'local': Remove only images that don't have a\n                              custom tag set by the `image` field.\n    -v, --volumes           Remove named volumes declared in the `volumes`\n                            section of the Compose file and anonymous volumes\n                            attached to containers.\n    --remove-orphans        Remove containers for services not defined in the\n                            Compose file\n    -t, --timeout TIMEOUT   Specify a shutdown timeout in seconds.\n\n```\n\n- Sample docker compose file yaml file\n\n```\nversion '1'\n\nconfigserver:\n  image: puneethkumarck/config-server\n  ports:\n    - \"8000:8000\"\n  depends_on:\n    - discovery\n    \ndiscovery:\n  image: puneethkumarck/eureka-server\n  ports:\n    - \"8761:8761\"\n\n\n```\n\n- docker compose logs command\n\n```\ndocker-compose logs -f\n\n```\n\n- docker compose option\n\n```\n- multiple projects using - p\n\n create multiple isolated environments on a host\n naming convention for naming docker container\n directoryname_servicename_servicenumber\n \n- default overrride\n  docker-compose.override.yml\n  \ncontent of docker-compose.override.yml\ndiscovery:\n  image: puneethkumarck/eureka-server\n  ports:\n    - \"8080:8761\"\n    \n  host port-\u003e 8080\n  contanier port -\u003e 8761\n```\n\n- docker compose Extends \n\n```\nconfiguration.yml\n\nversion '2'\nservices:\n  config:\n    environment:\n      AWS_ACCESS_KEY: XXXX\n      AWS_SECRET_KEY: XXXX\n      \n      \ndocker-compose.yml\n\nversion: '2'\nservices:\n  web:\n   extends:\n      file: configuration.yml\n      service: config\n   image: jboss/wildfly\n   volumes:\n     - ~/deployments:/opt/jboss/wildfly/standalone/deployments\n   ports:\n      - 8080:8080\n      \ndocker-compose --verbose up -d \n```\n\n- Docker compose Commands\n\n| Use case   | Command     |\n| ------------- |:-------------| \n| Dev setup     | docker-compose up| \n| local/remote host  | DOCKER_HOST , DOCKER_TLS_VERIFY ,DOCKER_CERT_PATH    |   \n| single/multiple host| integrated with swarm     |     \n| Multiple isolated environments | docker-compose up -p \u003cproject\u003e |\n| Automated test setup | docker-compose up , mvn test , docker-compose down |\n| Dev/prod impedance mismatch | docker-compose up -f docker-compose.yml -f production.yml |\n\nUseful commands\n================\n\n```\nRemove all the images from docker host using single line command instruction\ndocker image rm -f $(docker image ls -aq)\n\nRemove all the container running in docker host using single command line instruction\ndocker container rm -f $(docker container ls -aq)\n\n```\n\nReferences\n==========\n-  https://www.lynda.com/Docker-tutorials/Docker-Java-developers/576584-2.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpuneethkumarck%2Fdocker-command-tips","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpuneethkumarck%2Fdocker-command-tips","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpuneethkumarck%2Fdocker-command-tips/lists"}