docker-compose=> sh: 1: ./entrypointsh: not found but entrypoint shows in LS - docker

So I'm trying to set up a docker-compose file, and do some data initialisation in it. However when I do docker-compose up in my terminal (windows one + tried a bash one) I get sh: 1: ./entrypoint: not found despite it showing the file when I add ls to my command.
mssql_1 | data
mssql_1 | entrypoint.sh
mssql_1 | init.sql
mssql_1 | table
My docker-compose file:
version: '2.1'
services:
mssqldata:
image: microsoft/mssql-server-linux:latest
entrypoint: /bin/bash
mssql:
image: microsoft/mssql-server-linux:latest
ports:
- 1433:1433
volumes:
- /var/opt/mssql
- ./sql:/usr/src/app
working_dir: /usr/src/app
command: sh -c 'chmod +x ./entrypoint.sh; ./entrypoint.sh & /opt/mssql/bin/sqlservr;'
environment:
ACCEPT_EULA: Y
SA_PASSWORD: P#55w0rd
volumes_from:
- mssqldata
Folder structure:
docker-compose.yml
sql/
data/
table/
entrypoint.sh
init.sql

In my opinion this should be happening in your dockerfile instead of in your docker-compose.yml file. Generally the idea behind docker-compose is to get a multi container application running and to get the containers in a multi container application to talk to each other. So for example in your context it would perhaps be to get three containers to communicate with other for a asp.net+ MSSQL + IIS container.
In any case what you are trying to achieve you can do in your dockerfile
I'll try write this dockerfile for you as far as possible. Here is the dockerfile:
FROM microsoft/mssql-server-linux:latest
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
EXPOSE 1433
ADD entrypoint.sh /entrypoint.sh
COPY entrypoint.sh /entrypoint.sh
# I suggest you add starting : "/opt/mssql/bin/sqlservr" to the entrypoint.sh script it would simplify things a bit.
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
Here is the docker-compose.yml file that you need:
version: '2'
services:
ms-sql-server-container:
image: mssql-container:latest
# This refers to the docker container created by building our dockerfile with:
# docker build -t mssql-container .
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=P#55w0rd
volumes:
- ./sql:/usr/src/app
# I don't really understand the reason for the second volume that you had if you can kindly explain, then I can edit my answer to accomodate the second volume
# if I think that you need it.
ports:
- 1433:1433
Let me know if this works.

Related

How to add docker run param to docker compose file?

I am able to run my application with the following command:
docker run --rm -p 4000:4000 myapp:latest python3.8 -m pipenv run flask run -h 0.0.0.0
I am trying to write a docker-compose file so that I can bringup the app using
docker-compose up. This is not working. How do "add" the docker run params to the docker-compose file?
version: '3'
services:
web:
build: .
ports:
- "4000:4000"
volumes:
- .:/code
You need to use command to specify this.
version: '3'
services:
web:
build: .
ports:
- '4000: 4000'
image: myapp:latest
command: 'python3.8 -m pipenv run flask run -h 0.0.0.0'
volumes:
- .:/code
You should use CMD in your Dockerfile to specify this. Since you'll want to specify this every time you run a container based on the image, there's no reason to want to specify it manually when you run the image.
CMD python3.8 -m pipenv run flask run -h 0.0.0.0
Within the context of a Docker container, it's typical to install packages into the "system" Python: it's already isolated from the host Python by virtue of being in a Docker container, and the setup to use a virtual environment is a little bit tricky. That gets rid of the need to run pipenv run.
FROM python:3.8
WORKDIR /code
COPY Pipfile Pipfile.lock .
RUN pipenv install --deploy --system
COPY . .
CMD flask run -h 0.0.0.0
Since the /code directory is already in your image, you can actually make your docker-compose.yml shorter by removing the unnecessary bind mount
version: '3'
services:
web:
build: .
ports:
- "4000:4000"
# no volumes:

How to modify a Dockerfile with an existing ENTRYPOINT to add "wait-for-it.sh"?

I would like to modify the Docker image wrouesnel/postgres_exporter such that it can be used in a Docker Compose multi-container application and waits for Postgres to accept connections. My project has the following structure:
.
├── docker-compose.yml
└── exporter
├── Dockerfile
└── wait-for-it.sh
where docker-compose.yml reads
version: "3"
services:
db:
image: postgres
environment:
POSTGRES_PASSWORD: mypassword
networks:
- mynetwork
exporter:
build: exporter
environment:
DATA_SOURCE_NAME: "postgresql://postgres:mypassword#db:5432/postgres?sslmode=disable"
ports:
- "9187:9187"
networks:
- mynetwork
networks:
mynetwork:
and wait-for-it.sh is obtained from https://github.com/vishnubob/wait-for-it/blob/master/wait-for-it.sh, and the Dockerfile reads
FROM wrouesnel/postgres_exporter
COPY wait-for-it.sh wait-for-it.sh
ENTRYPOINT ["./wait-for-it.sh", "db:5432", "--", "./postgres_exporter"]
However, if I docker-compose build and attempt to docker-compose up, I get the following error:
> docker-compose up
Recreating postgres-performance-testing_exporter_1 ...
Recreating postgres-performance-testing_exporter_1 ... done
Attaching to postgres-performance-testing_db_1, postgres-performance-testing_exporter_1
exporter_1 | standard_init_linux.go:211: exec user process caused "no such file or directory"
I don't understand which file it is not finding and why not? Aren't both copied to my WORKDIR?
You can not run the bash script in wrouesnel/postgres_exporter image as wait-for-it.sh as wait-for-it is totaly based on bash.
if you look into Dockerfile of wrouesnel is from scratch and there is nothing in this image at all.
FROM scratch
ARG binary
COPY $binary /postgres_exporter
EXPOSE 9187
ENTRYPOINT [ "/postgres_exporter" ]
So the hack around with such an image is to use them as multi-stage image and copy the binaries and extend your image.
FROM wrouesnel/postgres_exporter
FROM debian:7.11-slim
RUN useradd -u 20001 postgres_exporter
USER postgres_exporter
COPY --from=0 /postgres_exporter /postgres_exporter
EXPOSE 9187
COPY wait-for-it.sh wait-for-it.sh
USER root
RUN chmod +x wait-for-it.sh
USER postgres_exporter
RUN pwd
ENTRYPOINT ["./wait-for-it.sh", "db:5432", "--", "./postgres_exporter"]

container keep exiting right after running it

docker-compose.yaml:
web:
build: .
command: ./main
ports:
- "8888:3412"
volumes:
- .:/code
links:
- redis
redis:
image: redis
Dockerfile:
FROM golang:1.6
ADD main.go .
EXPOSE 3412
ENTRYPOINT /go
RUN go build main.go
so after running docker run -d imagename, there is no running container
also docker logs containername doesn't show anything
ENTRYPOINT /go
is equivalent to running /bin/sh -c /go
go is actually a directory in your container, so it will fail, because shell cannot execute a directory.
remove the background flag -d and use docker run imagename and you will see this error
What you probably want is:
ENTRYPOINT /usr/local/go/bin/go to use go as an executable from the container.
Or even better:
ENTRYPOINT ["/usr/local/go/bin/go"], so you would be able to pass arguments to go.

mkdir and copy files vs volume for webpack in docker

I am trying to get webpack setup on my docker container. It is working, and running, but when I save on my local computer it is not updating my files in my container. I have the following docker-compose file:
version: '2'
services:
web:
build:
context: .
dockerfile: docker/web/Dockerfile
container_name: arc-bis-www-web
restart: on-failure:3
environment:
FPM_HOST: 'php'
ports:
- 8080:8080
volumes:
- ./app:/usr/local/src/app
php:
build:
context: .
dockerfile: docker/php/Dockerfile
environment:
CRM_HOST: '192.168.1.79'
CRM_NAME: 'ARC_test_8_8_17'
CRM_PORT: '1433'
CRM_USER: 'sa'
CRM_PASSWORD: 'Multi*Gr4in'
volumes:
- ./app:/usr/local/src/app
node:
build:
context: .
dockerfile: docker/node/Dockerfile
container_name: arc-bis-www-node
volumes:
- ./app:/usr/local/src/app
and my node container is run by the following dockerfile:
FROM node:8
RUN useradd --create-home user
RUN mkdir /usr/local/src/app
RUN mkdir /usr/local/src/app/src
RUN mkdir /usr/local/src/app/test
WORKDIR /usr/local/src/app
# Copy application source files
COPY ./app/package.json /usr/local/src/app/package.json
COPY ./app/.babelrc /usr/local/src/app/.babelrc
COPY ./app/webpack.config.js /usr/local/src/app/webpack.config.js
COPY ./app/test /usr/local/src/app/test
RUN chown -R user:user /usr/local/src/app
USER user
RUN npm install
ENTRYPOINT ["npm"]
Now I have taken out the copy calls from above and it still runs fine, but neither option is allowing me to save files locally and have them show up in the localhost for my container. Ideally, I thought having a volume would allow me to update my local files and have it read by the volume in the container. Does that make sense? I am still feeling my way around Docker. Thanks in advance for any help.
If you start your container with -v tag, you can map the container and your local storage. You can find more information here.

named docker volume not updating using docker-compose

I'm trying to have one service to build my client side and then share it to the server using a named volume. Every time I do a docker-compose up --build I want the client side to build and update the named volume clientapp:. How do I do that?
docker-compose.yml
version: '2'
volumes:
clientapp:
services:
database:
image: mongo:3.4
volumes:
- /data/db
- /var/lib/mongodb
- /var/log/mongodb
client:
build: ./client
volumes:
- clientapp:/usr/src/app/client
server:
build: ./server
ports:
- "3000:3000"
environment:
- DB_1_PORT_27017_TCP_ADDR=database
volumes:
- clientapp:/usr/src/app/client
depends_on:
- client
- database
client Dockerfile
FROM node:6
ENV NPM_CONFIG_LOGLEVEL warn
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app
RUN npm install
COPY . /usr/src/app
# builds my application into /client
CMD ["npm", "build"]
By definition, a volume is the persistent directories that docker won't touch other than to perform an initial creation when they are empty. If this is your code, it probably shouldn't be a volume.
With that said, you can:
Delete the volume between runs with docker-compose down -v and it will be recreated and initialized on the next docker-compose up -d.
Change your container startup scripts to copy the files from some other directory in the image to the volume location on startup.
Get rid of the volume and include the code directly in the image.
I'd recommend the latter.
Imagine you shared your src folder like this :
...
volumes:
- ./my_src:/path/to/docker/src
...
What worked for me is to chown the my_src folder :
chown $USER:$USER -R my_src
It turned out some files were created by root and couldn't be modified by docker.
Hope it helps !

Resources