Home > Blockchain >  How come when I edit the /usr/local/bin/docker-entrypoint.sh file nothing happens?
How come when I edit the /usr/local/bin/docker-entrypoint.sh file nothing happens?

Time:12-16

I create a container off the node docker image. Then I go into the container with bash and try to edit the entrypoint file but the changes I make inside don't get executed. Like I told it to make a directory in the root path of the container called /app I stop and start the container but the change doesn't happen. Here's the file

#!/bin/sh
set -e

mkdir /app

# Run command with node if the first argument contains a "-" or is not a system command. The last
# part inside the "{}" is a workaround for the following bug in ash/dash:
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=874264
if [ "${1#-}" != "${1}" ] || [ -z "$(command -v "${1}")" ] || { [ -f "${1}" ] && ! [ -x "${1}" ]; }; then
  set -- node "$@"
fi

exec "$@"

CodePudding user response:

By the time you're making this change, the entrypoint script has already executed. A container runs one process, and it's the entrypoint script; there's no way to re-run it without re-running the container. If you docker rm the old container and docker run a new one, the change you made to the file will be lost.

As a matter of general process I'd suggest avoiding "going into the container". If you need to make a change in a script like this, change it on the host, docker build && docker run a new image with the change, and then commit the changed file to source control. If you change your application code, npm test it on the host, then docker build && docker run a new image, and commit the updated code and unit tests to source control.

For your particular use case, if the container should always contain a directory named /app, I'd recommend creating it in the image's Dockerfile rather than trying to create it dynamically when the container starts up.

FROM node:lts
RUN mkdir /app
...

More generally, your image should contain the filesystem layout and code you need to run your application. For most Node applications I'd expect a Dockerfile to look something like

FROM node:lts
WORKDIR /app
COPY package*.json .
RUN npm ci
COPY . .
CMD node ./index.js

(where you also have a .dockerignore file that excludes the host's node_modules tree.)

Docker's Sample application tutorial describes this sequence in more detail, including a different Node-based example.

  • Related