I use Fedora 35 Silverblue.
I followed this article on how to make podman and docker-compose friends in rootless mode.
I made a simple project:
.
├── docker-compose
│ └── app
│ ├── Dockerfile
│ └── entrypoint.sh
└── docker-compose.yml
Permissions for docker-compose/app/entrypoint.sh are -rwxrwxr-x..
docker-compose.yml:
version: '3.7'
services:
app:
container_name: app
image: app
build:
context: .
dockerfile: docker-compose/app/Dockerfile
volumes:
- .:/usr/src/app
entrypoint: docker-compose/app/entrypoint.sh
docker-compose/app/Dockerfile:
FROM ruby
WORKDIR /usr/src/app
docker-compose/app/entrypoint.sh:
#!/bin/bash
echo "Hello world"
When I run docker-compose up --build I receive:
Removing app
Building app
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
STEP 1/2: FROM ruby
STEP 2/2: WORKDIR /usr/src/app
--> Using cache 39d51dee76399b2b7f06dc174e240f55b57acf4608a639146c0f67fd22b5bdb6
COMMIT app
--> 39d51dee763
Successfully tagged localhost/app:latest
Successfully tagged localhost/test-compose_app:latest
39d51dee76399b2b7f06dc174e240f55b57acf4608a639146c0f67fd22b5bdb6
Recreating 9b852c5536a3_app ... done
Attaching to app
app | /bin/bash: /usr/src/app/docker-compose/app/entrypoint.sh: Permission denied
app exited with code 126
So, it can run the entrypoint though can't access the bash inside container as far as I understand.
The same project runs ok on MacOs though with docker.
If I copy the entrypoint in dockerfile it works but I don't want to rebuild my image every time I change something in entrypoint.
Is there a possibility to resolve this issue?
Thank you in advance
UPD: It doesn't work even if entrypoint is copied
docker-compose/app/Dockerfile
FROM ruby
COPY docker-compose/app/entrypoint.sh /entrypoint.sh
ENTRYPOINT /entrypoint.sh
WORKDIR /usr/src/app
docker-compose/app/entrypoint.sh
#!/bin/bash
echo "Hello world"
whoami
pwd
ls -la .
$ docker-compose up --build
Building app
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
STEP 1/4: FROM ruby
STEP 2/4: COPY docker-compose/app/entrypoint.sh /entrypoint.sh
--> Using cache 6da30c949d2f7c7cf1f4a293c3f4aebe23843e87a124317afafe67cdc117e6ab
--> 6da30c949d2
STEP 3/4: ENTRYPOINT /entrypoint.sh
--> Using cache 6fdcaf571d83ac713235b0bb3c816f707b4257b6f55911675ef65a91d981c41d
--> 6fdcaf571d8
STEP 4/4: WORKDIR /usr/src/app
--> Using cache 70f7f580ac7dd13fdace59fe2bc26c694105f76e9c87a33fc24b38299438b216
COMMIT app
--> 70f7f580ac7
Successfully tagged localhost/app:latest
70f7f580ac7dd13fdace59fe2bc26c694105f76e9c87a33fc24b38299438b216
Recreating app ... done
Attaching to app
app | Hello world
app | root
app | /usr/src/app
app | ls: cannot open directory '.': Permission denied
app exited with code 2
Seems like user inside container lacks the permissions but user is root...
It looks like you're running on a system running SELinux. You need to modify your bind mount to modify the labelling of your file to make it accessible inside the container:
version: '3.7'
services:
app:
container_name: app
image: app
build:
context: .
dockerfile: docker-compose/app/Dockerfile
volumes:
- .:/usr/src/app:z
entrypoint: docker-compose/app/entrypoint.sh
Note the :z added to the bind mount.
Related
MySql Router has a command to bootstrap itself
mysqlrouter --bootstrap root#127.0.0.1:3306 --directory /tmp/router
After bootstrap, Router will exit, and we should run it again with config file generated by bootstrap since I will modify this file
mysqlrouter --config /tmp/router/mysqlrouter.conf
It's work ok in Linux pure environment, but not in docker, below is my docker compose file
version: '2'
services:
common: &baseDefine
environment:
MYSQL_HOST: "192.168.213.6"
MYSQL_PORT: 3306
MYSQL_USER: 'root'
MYSQL_PASSWORD: 'urpwd.root'
MYSQL_INNODB_CLUSTER_MEMBERS: 3
MYSQL_CREATE_ROUTER_USER: 0
image: "docker.io/mysql/mysql-router:latest"
volumes:
- "./conf:/tmp/myrouter"
network_mode: "host"
boot:
container_name: "mysql_router_boot"
command: ["mysqlrouter","--bootstrap","root#192.168.213.7:3306","--directory","/tmp/myrouter","--conf-use-sockets","--conf-skip-tcp",
"--force","--strict","--user","mysqlrouter","--account","sqlrouter","--account-create","if-not-exists"]
<<: *baseDefine
run:
container_name: "mysql_router"
restart: always
command: ["mysqlrouter","--config","/tmp/myrouter/mysqlrouter.conf"]
<<: *baseDefine
First, I will call the boot service for bootstrap, and generate configure to specified dir
docker-compose run --rm boot
after this command, the configure file is generated ok, then I execute
docker-compose run --name mysql_router run
It will work, but not work like what I supposed,
Without docker, the second step to run mysqlrouter only use config and without bootstrap
But with docker and those commands, the second step will bootstrap again.
I know this is since 2 service in 2 containers.
Is there any ideas to make this flow more suitable?
Such as run 2 service in one container?
Or run a service in an existed container?
It's ok with below:
modify yml's command of run service
run:
command: /bin/bash -c "mysqlrouter --config /tmp/myrouter/mysqlrouter.conf"
use bash to run mysqlrouter delay for recognizing the existed conf file;
it works
I'm trying to run a database in docker and a python script with it to store MQTT messages. This gave me the idea to use Docker Compose since it sounded logical that both were somewhat connected. The issue I'm having is that the Docker Containers do indeed run, but they do not store anything in the database.
When I run my script locally it does store messages so my hunch is that the Compose File is not correct.
Is this the correct way to compose a python file which stores message in a DB and the database itself (with a .js file for the credentials). Any feedback would be appreciated!
version: '3'
services:
storing_script:
build:
context: .
dockerfile: Dockerfile
depends_on: [mongo]
mongo:
image: mongo:latest
environment:
MONGO_INITDB_ROOT_USERNAME: xx
MONGO_INITDB_ROOT_PASSWORD: xx
MONGO_INITDB_DATABASE: motionDB
volumes:
- ${PWD}/mongo-data:/data/db
- ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
ports:
- 27018:27018
restart: unless-stopped
The DockerFile im using to build:
# set base image (host OS)
FROM python:3.8-slim
# set the working directory in the container
WORKDIR /code
# copy the dependencies file to the working
directory
COPY requirements.txt .
# install dependencies
RUN pip install -r requirements.txt
# copy the content of the local src directory to
the working directory
COPY src/ .
# command to run on container start
CMD [ "python", "./main.py"]
I think this may be due to user permission.
What I did for my docker-compose for docker deployment, is I also mount the passwd file after creating a mongodb user
volumes:
/etc/passwd:/etc/passwd:ro
This worked for me as the most straight forward solution.
I am trying to run an ASP.net core API in a Docker container. Running from Visual Studio works perfectly fine, but I cant access the API when I run it using the following powershell command:
docker run --name test6 --rm -it -p 9001:80 webapplication6:dev
It just return:
root#874b63595efc:/app#
I expect that it will show me that it has started listening to the given port. I tried to use an existing repo from Docker Hub to do a test:
docker run --name aspnetcore_sample --rm -it -p 8000:80 mcr.microsoft.com/dotnet/core/samples:aspnetapp
And it successfully returned the following:
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://[::]:80
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: /app
It is accessible in my localhost. Going back to my test API project, I have the following text in my Dockerfile:
FROM mcr.microsoft.com/dotnet/core/aspnet:2.1-stretch-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:2.1-stretch AS build
WORKDIR /src
COPY ["WebApplication6.csproj", ""]
RUN dotnet restore "./WebApplication6.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "WebApplication6.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WebApplication6.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication6.dll"]
This was automatically added by Visual Studio.
Here is the output being returned by docker ps
The command value for my test application is "bash". Do I need to configure anything else for me to run the API container using Powershell alone and without using Visual Studio?
Seems like docker engine is ignoring the entrypoint directive in your Dockerfile, as you can see the command is null in your running container.
You can probably work around this issue by specifying a CMD directive in your Dockerfile. Try adding this line to the bottom of your Dockerfile and see if it helps:
CMD ["dotnet", "WebApplication6.dll"]
Also, make sure that your docker image is built with the current version of the Dockerfile, you can try using this command to verify that:
docker build -t webapplication6:dev .
I have the following docker-compose file
version: '3'
services:
web:
container_name: chatt-friends-api
volumes:
- .:/usr/src/appDev
ports:
- 3000:3000
env_file: docker/web-Dockerfile.env
build:
context: .
dockerfile: docker/web-Dockerfile.yml
with the following directory structure
Now when I run docker-compose up and move into the chatt-friends-api container and navigate into the appDev folder. I see two folders inside which are docker, and node_modules. I have no idea why this is so. For your reference this is what web-Dockerfile.yml looks like. I'm copying the whole src folder here anyway, but was trying to see if the volumes get mounted properly as well.
from node:latest
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm#5+)
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD [ "npm", "start" ]
I am going to post the answer here in case someone else has the problem. I was primarily using VirtualBox on Windows 8 and this has to do with shared folders. You need to share a folder and map it to a version unix understands.
The answer is explained here quite well
Docker volumes mounting on Windows 8 is not working
I utilize HapiJS via docker compose 2+
.env
NODE_VIEWS_PATH=../
NODE_PUBLIC_PATH=../
MONGODB_URI=mongodb://127.0.0.1:27017/mahrio
WEB_DOMAIN=http://127.0.0.1:6085
deep down somewhere I am setting the HapiJS stuff via these .env files, but for Docker I understand I need to do some changes.. no problem I made a docker specific version
docker.env
NODE_VIEWS_PATH=../
NODE_PUBLIC_PATH=../
MONGODB_URI=mongodb://mongo:27017/mahrio
WEB_DOMAIN=http://0.0.0.0:6085
I've tried 0.0.0.0 and 127.0.0.1 , neither work
I can see everything seems to work however when I goto localhost:6085 I get no response.
127.0.0.1 didn’t send any data.
Dockerfile
FROM node:carbon
# Create app directory
RUN mkdir -p /usr/src/mahrio
WORKDIR /usr/src/mahrio
COPY package*.json /usr/src/mahrio
RUN npm install
# If you are building your code for production
# RUN npm install --only=production
COPY . /usr/src/mahrio
EXPOSE 6085
CMD ["npm", "start"]
docker-compose.yml
version: "2"
services:
app:
build: .
container_name: mahrio
depends_on:
- mongo
env_file:
- docker.env
ports:
- "6085:6085"
restart: always
mongo:
container_name: mongo
image: mongo
volumes:
- ./tmp:/data/db
ports:
- "27017:27017"
any ideas ? No errors from nodejs are coming, everything looks A-OKAY at the console and I know it works outside docker just fine.
Edit: added the docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
25e7a4c3f350 mahriomedium_app "npm start" 24 hours ago Up About a minute 0.0.0.0:6085->6085/tcp mahrio
c8d691777aa0 mongo "docker-entrypoint..." 3 days ago Up About a minute 0.0.0.0:27017->27017/tcp mongo
docker logs
> mahrio-medium#0.0.1 start /usr/src/mahrio
> node server/index.js
Running Development!
MongoDB Config...
Server running at: http://127.0.0.1:6085
MongoDB connected!
db connection opened
it turned out WEB_DOMAIN was the wrong env var
the right var is NODE_URI to set to 0.0.0.0
all works now