Flag provided but not defined - docker

I have following Dockerfile:
FROM golang:1.9.2
ADD . /go/src/github.com/golang/example/outyet
ADD . /go/src/github.com/derekparker/delve/cmd/dlv
RUN go install github.com/golang/example/outyet
RUN go install github.com/derekparker/delve/cmd/dlv
RUN ["chmod", "+x", "/go/src/github.com/golang/example/outyet/bootstrap.sh"]
CMD ["/go/src/github.com/golang/example/outyet/bootstrap.sh"]
EXPOSE 8091
EXPOSE 5432
And following bootstrap.sh:
#!/bin/sh
go build -gcflags='-N -l' github.com/golang/example/outyet &&
dlv --listen=:5432 --headless=true --api-version=2 exec outyet;
After running container and image with following lines:
sudo docker build -t outyet .
sudo docker run -p 6060:8091 -p 5432:5432 --name test --rm outyet
I get following output:
flag provided but not defined: -listen
Usage of dlv:
-http string
Listen address (default ":8091")
-poll duration
Poll period (default 1s)
-version string
Go version (default "1.4")
When I run bootstrap.sh locally on my ubuntu hostmachine everything works fine. What is wrong?

I was able to fix it, my Dockerfile looks like this now:
FROM golang:1.9.2
ADD . /go/src/github.com/golang/example/outyet
RUN go install github.com/golang/example/outyet
RUN ["chmod", "+x", "/go/src/github.com/golang/example/outyet/bootstrap.sh"]
RUN ["chmod", "+x", "/go/bin/outyet"]
CMD ["/go/src/github.com/golang/example/outyet/bootstrap.sh"]
EXPOSE 8091
EXPOSE 5432
bootstrap.sh:
#!/bin/sh
go get github.com/derekparker/delve/cmd/dlv;
go build -gcflags='-N -l' github.com/golang/example/outyet &&
dlv --listen=:5432 --headless=true --api-version=2 exec outyet
And run it as following:
sudo docker build -t outyet .
sudo docker run --security-opt=seccomp:unconfined --net=host --name test --rm outyet

Related

Docker volume mapping to current working directory not work

Docker version 20.10.21
docker run command with -v option works as expected when the destination path is other than /app. But when the destination path is /app it doesn't work as expected.
command works as expected:
docker run -d -v ${pwd}:/app2 react-app
command not works as expected:
docker run -d -v ${pwd}:/app react-app
as seen in the snapshot there is not port for the second container
here is Dockerfile content
FROM node:14.16.0-alpine3.13
RUN addgroup app && adduser -S -G app app
USER app
WORKDIR /app
RUN mkdir data
COPY package*.json .
RUN npm install
COPY . .
ENV API_URL=http://api.myapp.com/
EXPOSE 3000
CMD [ "npm", "start" ]
You are running npm install in /app in the Dockerfile, but then at runtime you are mounting pwd over the files you installed in /app during the build process. Don't install your dependencies in /app during the build if you want to mount to /app at runtime.
Please try using $(pwd) instead of ${pwd}. Also if you are running it under Windows then you probably need to use some shell which implements pwd command correctly. E.g. Git Bash.
docker run -d -v $(pwd):/app react-app
Also once you start the container please check docker container inspect <container ID>, specifically Mounts section.
Or you can filter the output:
docker container inspect <container ID> -f '{{ .Mounts }}'
Also if you see that container exits immediately, please check its logs with
docker logs <container ID>
I solved it by excluding the node_modules from the mounting as:
docker run -d -v ${pwd}:/app -v /app/node_modules react-app

docker container stops after docker run

I have a docker file which when built and run stops. I am trying to run both client and server in one docker container. If there is any solution to use docker-compose, then that is already in place and working fine. Please advise how to keep the container up and running using docker run. Thanks!
Here is my docker file, package.json and screenshot of folder structure.
DockerFile contents:
FROM node:14.14.0-alpine
RUN apk update && apk add bash
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
WORKDIR /app
EXPOSE 3000
EXPOSE 4565
CMD ["npm","run","prebuild"]
docker build: command:
docker build -t sample .
docker run command:
docker run -d -it --name sm -v `pwd`:/app sample
Package.json:

executing a simple go .exe in a dockerfile

I have the following dockerfile and everything works fine except for running the .exe
FROM golang:latest
# Set the Current Working Directory inside the container
WORKDIR $GOPATH/src/github.com/user/goserver
# Copy everything from the current directory to the PWD (Present Working Directory) inside the container
COPY . .
# Download all the dependencies
RUN go get -d -v ./...
# Install the package
RUN GOOS=linux GOARCH=amd64 go build -o goserver .
# This container exposes port 8080 to the outside world
EXPOSE 8080
# Run the executable
CMD ./goserver
The problem is that it does not execute './goserver'. I need to manually go into the container and then execute it. Any idea what could be going wrong here ?
The problem is the way you are running the container.
By running the container with the following:
docker run -it -p 8080:8080 goserver /bin/bash
you are overriding the command defined with CMD in Dockerfile to bin/bash command.
You can start the container in detached mode by running it as:
docker run -d -p 8080:8080 goserver
Further, if you want to later exec into the container then you can use the docker exec command.

Container is exiting on its own & not able to exec into it

I am trying to build and container image & then trying to run the enter the container after running it. But I am getting error response from daemon.
My Docker file -
COPY . /app
RUN sudo chmod 777 -R /app
WORKDIR /app
ADD entry_point.sh /opt/bin/
RUN sudo chmod 777 /opt/bin/entry_point.sh
COPY start-selenium-standalone.sh /opt/bin/start-selenium-standalone.sh
RUN sudo chmod 777 /opt/bin/start-selenium-standalone.sh
EXPOSE 4444 5900 9515
**Command to build docker image**
docker build -f Docker/Dockerfile -t sel-test:1 .
**Command to run the image**
docker run -d -p 4444:4444 -p 5900:5900 -v /dev/shm:/dev/shm sel-test:1
**Error I am getting -**
Error response from daemon: Container a9e0bb7f381584dd5e39dcd997640233835408ffdfe4e0e44108ddb7bb393cd0 is not running
Your container is exiting because there is nothing to run inside the container.
To see this, run the docker ps -a command and check the status of your container.
In order to run something inside the container use CMD in docker file to run bash inside the container whenever you use 'docker run'.

Docker Container is not running

Please help. When I want to go into a container is says
Error response from daemon: Container 90599013c666d332ff6560ccde5053d9127e72042ecc3887550aef90fa1d1eac is not running
My DockerFile:
FROM ubuntu:16.04
MAINTAINER Anton Lapitski <a.lapitski#godeltech.com>
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
ADD ./ /usr/src/app
EXPOSE 80
ENTRYPOINT ["/bin/sh", "-c", "/usr/src/app/entry.sh"]
Starting script - start.sh:
sudo docker build -t starter .
sudo docker run -t -v mounted-directory:/usr/src/app/mounted-directory -p 80:80 starter
entry.sh script:
echo "Hello World"
ls -l
pwd
if mountpoint -q /mounted-directory
then
echo "mounted"
else
echo "not mounted"
fi
sudo docker ps -a gives:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
90599013c666 starter "/bin/sh -c /usr/src…" 18 minutes ago Exited (0) 18 minutes ago thirsty_wiles
And mosе important:
sudo docker exec -it 90599013c666 bash
Error response from daemon: Container 90599013c666d332ff6560ccde5053d9127e72042ecc3887550aef90fa1d1eac is not running
Please could you tell what I am doing wrong?
P.S adding -d flag when running not helped.
Once the ENTRYPOINT completes (in any form), the container exits.
Once the container exits, you can't docker exec into it.
If you want to get a shell on the image you just built to poke around in it, you can
sudo docker run --rm -it --entrypoint /bin/sh starter
To make this slightly easier to run, you might change ENTRYPOINT to CMD in your Dockerfile. (Docker will run the ENTRYPOINT passing the CMD as command-line arguments; or if there is no entrypoint just run the CMD.)
...
RUN chmod +x ./app.sh
CMD ["./app.sh"]
Having done that, you can more easily override the command
sudo docker run --rm -it starter /bin/sh
You can try
docker start container_id and then docker exec -ti container_id bash for a stopped container.
You cannot execute the container, because your ENTRYPOINT script has been finished, and the container stopped. Try this:
Remove the ENTRYPOINT from your Dockerfile
Rebuild the image
run it with sudo docker run -it -v mounted-directory:/usr/src/app/mounted-directory -p 80:80 starter sh
The key is the i flag and the sh at the end of the command.
I tried these two commands and it works:
sudo docker start <container_id>
docker exec -it <containerName> /bin/bash

Resources