Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

entrypoint: "entrypoint.sh" - docker compose

There is no such file by name entrypoint.sh in my workspace.

But below instruction in docker-compose.yml is referring it:

builder: 
  build: ../../
  dockerfile: docker/dev/Dockerfile
  volumes:
    - ../../target:/wheelhouse
  volumes_from:
    - cache
  entrypoint: "entrypoint.sh"
  command: ["pip", "wheel", "--non-index", "-f /build", "."]

where ../docker/dev/Dockerfile has

# Set defaults for entrypoint and command string
ENTRYPOINT ["test.sh"]
CMD ["python", "manage.py", "test", "--noinput"]

What does entrypoint: "entrypoint.sh" actually do?

like image 570
overexchange Avatar asked Oct 17 '19 17:10

overexchange


People also ask

What is docker entrypoint sh for?

Introduction of Docker ENTRYPOINT. Docker entrypoint is a Dockerfile directive or instruction that is used to specify the executable which should run when a container is started from a Docker image.

What is entrypoint docker compose?

Well, in essence, an EntryPoint provides a method for you to execute a command within a container, either at build time, or when the container is first run.

Does docker compose command override entrypoint?

All About Docker Compose Override Entrypoint Entrypoint helps use set the command and parameters that executes first when a container is run. In fact, the command line arguments in the following command become a part of the entrypoint command, thereby overriding all elements mentioned via CMD.

How do I run multiple commands in docker compose?

We can also use the | operator to run multiple commands in Docker Compose. The syntax of the | operator is a bit different from the && operator. Here, we added the commands on separate lines. Everything is the same except for the command instruction.

How to run entrypoint commands in a docker container?

Another option is to use a script to run entrypoint commands for the container. By convention, it often includes entrypoint in the name. In this script, you can setup the app as well as load any configuration and environment variables. Here is an example of how you can run it in a Dockerfile with the ENTRYPOINT exec syntax.

What is entrypoint SH in dockerfile?

entrypoint.sh pip wheel --non-index -f /build . So basically, entrypoint.sh is a script that will run inside your container builder when you execute docker-compose up command. Also you can check this answer for more info What is the difference between CMD and ENTRYPOINT in a Dockerfile?

What is the ‘Exec’ form in Docker?

The ‘exec’ form allows us to specify the command line arguments to the ‘docker run’ command and it is appended to the end of all elements of the ‘exec’ form which means the specified command will run after the executable specified in entrypoint.

What is entrypoint in Linux?

Entrypoint sets the command and parameters that will be executed first when a container is run. What does Entrypoint do? Entrypoint sets the command and parameters that will be executed first when a container is run.


3 Answers

entrypoint: "entrypoint.sh" overrides ENTRYPOINT ["test.sh"] from Dockerfile.

From the docs:

Setting entrypoint both overrides any default entrypoint set on the service’s image with the ENTRYPOINT Dockerfile instruction, and clears out any default command on the image - meaning that if there’s a CMD instruction in the Dockerfile, it is ignored.

  • ENTRYPOINT ["test.sh"] is set in Dockerfile describing docker image

  • entrypoint: "entrypoint.sh" is set in docker-compose file which describes multicontainer environment while referencing the Dockerfile.

  • docker-compose build builder will build image and set entrypoint to ENTRYPOINT ["test.sh"] set in Dockerfile.

  • docker-compose up builder will start container with entrypoint entrypoint.sh pip wheel --no-index '-f /build' . set in docker-compose file

like image 153
rok Avatar answered Oct 19 '22 21:10

rok


ENTRYPOINT is a command or script that is executed when you run the docker container.

If you specify entrypoint in the docker-compose.yaml, it overrides ENTRYPOINT from specified Dockerfile.

CMD is something that is passed as the parameters to the ENTRYPOINT

So if you just run the dev/Dockerfile, it would execute

test.sh python manage.py test --noinput

If you overrided CMD in docker-compose.yaml as you did, it would execute

test.sh pip wheel --non-index -f /build .

But because you also overrided ENTRYPOINT in your docker-compose.yaml, it is going to execute

entrypoint.sh pip wheel --non-index -f /build .

So basically, entrypoint.sh is a script that will run inside your container builder when you execute docker-compose up command.

Also you can check this answer for more info What is the difference between CMD and ENTRYPOINT in a Dockerfile?

like image 33
Tomas Bruckner Avatar answered Oct 19 '22 20:10

Tomas Bruckner


Update: If the base image has entrypoint.sh, it will run that, but if you override with your own entrypoint then the container will run the override entrypoint.

If you to override the default behaviour of base image then you can change, ohterwise you do not need to override it from docker-compose.

What does entrypoint: "entrypoint.sh" actually do?

It totally depend on the script or command inside entrypoint.sh, but few things can be considered.

ENTRYPOINT instruction allows you to configure a container that will run as an executable. It looks similar to CMD, because it also allows you to specify a command with parameters. The difference is ENTRYPOINT command and parameters are not ignored when Docker container runs with command line parameters. (There is a way to ignore ENTTRYPOINT, but it is unlikely that you will do it.)

In simple word, entrypoint can be a complex bash script, for example in case of mysql entrypoint which is more then 200 LOC which does the following task.

  • start MySQL server
  • wait for MySQL server to up
  • Create DB
  • Can perform DB migration or DB initlization

So much complex task is not possible with CMD, as in CMD you can run the bash but it will be more headache to make it work. Also it make Dockerfile simple and put the complex task to entrypoint.

When there is entrypoint, anything that is passed to CMD will be consider as a argument for entrypoint.

In your case, CMD is CMD ["python", "manage.py", "test", "--noinput"] it will be passed as an argument and the best to run this is to use use

# set of command
#start long running process at the end that is passed from CMD
exec "$@"

Finally, the exec shell construct is invoked, so that the final command given becomes the container's PID 1. $@ is a shell variable that means "all the arguments",

use-a-script-to-initialize-stateful-container-data

cmd-vs-entrypoint

like image 2
Adiii Avatar answered Oct 19 '22 21:10

Adiii