Posted on
  1. Docker run vs Docker exec: Docker run is typically used for images. This command is used when you want to spin up a container from an image. Let's say you want to go inside the terminal of a docker container that you want to spin from the image, the command that is used is like this: docker run -it <image-name> bash

Docker exec is used for containers. Let's say we already have a container that is running and we want to enter it's bash (just like the case highlighted above), we can run the command: docker exec -it <container-name> bash

  1. Entrypoint and commands are two important concepts in Docker. Quoting a stack overflow explaination for the same: a. Docker has a default entrypoint but it does not have a default command. The default entrypoint is /bin/sh -c. Commands on the other hand, need to be passed. Everything after the image name in docker run -it <image-name> is a command, which is run via the entrypoint. The CMD mentioned in the dockerfile also act like commands which you don't have to explicitly pass when running docker run b. When you run the command docker run -it <image-name> bash. The command is run via the entrypoint. i.e., the actual thing that gets executed is /bin/sh -c bash. c. Entrypoint can be customised using --entrypoint flag

  2. Container names generated by default can be weird and confusing, so it is a good practice to name the containers that are being spun up with --name flag. E.g.: docker run --name <container-name-that-you-want> -it <image-name>