Giter VIP home page Giter VIP logo

friendnet's Introduction

Host port and container port

  • The container port is not the host port even if the container port is 3000, the host port is 3000. so we need to map the container port to the host port.

Security fails if we leave the container with the root user

  • We need to create a user in the container and run the app with that user. for that we need add the following lines to Dockerfile: RUN addgroup app && adduser -S -G app app USER app

default CMD after build the image

  • We can supply a default command to be executed when the container starts. for example : CMD npm start

the difference between CMD and RUN

  • RUN is a build time instruction, it is executed in the image build time.
  • CMD is a run time instruction, it is executed when the container starts.

The difference between CMD shell and CMD exec

  • it's a best practice to use CMD exec instead of CMD shell because it runs the command directly without creating another shell process, so it makes cleaning containers easier.

The difference between ENTRYPOINT and CMD

  • ENTRYPOINT is like CMD exec but it can't be overridden by default, if we need to override it we need to use the --entrypoint flag. in other hand CMD can be overridden by default.

Free up space

  • To remove all stopped containers: docker container prune

  • To remove all unused images (dangling images): docker image prune

  • delete a container: docker rm <container_id>

  • delete an image: docker rmi <image_id>

Tagging images

  • Tags are used for the versioning of the images, for example: docker build -t <imagename>:<tag> .
  • a tag can be a version number like 3.0.0 or a build number like 73 etc. and it can be configured in the CI/CD pipeline to be incremented automatically.
  • to retag an image: docker tag <old_image_name>:<old_tag> <new_image_name>:<new_tag>
  • remove a tag: docker image remove <image_name>:<tag>
  • upgrade to latest tag: docker tag <image_name>:<tag> <image_name>:latest or docker tag imageid <image_name>:latest

Pushing images to Docker Hub

first we build the image then we need to tag it with the docker hub username and the repository name then we need to login to the docker hub and push the image. docker image tag <image_name>:<tag> <docker_hub_username>/<repository_name>:<tag> docker login docker push <docker_hub_username>/<repository_name>:<tag>

example: docker image tag friendnetserver:2 haitamelgharras/friendnet_server:2 docker login docker push haitamelgharras/friendnet_server:2

Saving and loading images

  • To save an image to a file: docker save -o <filename>.tar <image_name>:<tag> example: docker save -o friendnetsrv.tar friendnetserver:2

  • To load an image from a file: docker load -i <filename>.tar example: docker load -i friendnetsrv.tar

  • Note that .tar is a compressed file like .zip in windows.

  • mount a drive: sudo mount -t drvfs E: /mnt/e

To learn more about any command

docker <command> --help

friendnet's People

Contributors

haitam-elgharras avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.