I have a nodejs app, which has some test return with mocha:
I have a docker-compose.yml with the following:
app:
image: alvin/node
working_dir: /app
command: node app.js
volumes:
- .:/app
ports:
- "3000:3000"
environment:
- NODE_ENV=development
When I run docker-compose up, it works:
Recreating node_app_1
Attaching to node_app_1
[36mapp_1 |[0m Sever listen to port: 3000
But when I run docker-compose run -d app mocha, it does not return any result on the terminal. alvin/node docker image has mocha install globally.
Passing the -d option specifically tells the containers to run in the background, so you naturally won't get the result on standard out. If you want to pick the result up, you can explicitly ask for the container's logs.
First find the container id via docker ps:
> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2a7901d40982 nginx "nginx -g 'daemon off" 7 seconds ago Up 6 seconds 80/tcp, 443/tcp loving_brattain
Then use docker logs $CONTAINER_ID.
> docker logs 2a7901d40982
Related
I'm trying to understand why I can't see containers created with docker-compose up -d using docker ps. If I go to the folder where is the docker-compose.yaml located and run docker-compose ps I can see the container runing. I did the same on windows because i'm using ubuntu and it works as expected, I can see the container just runing docker ps. Could anyone give me a hint about this behavior, please? Thanks in advance.
Environment:
Docker version 20.10.17, build 100c701
docker-compose version 1.25.0, build unknown
Ubuntu 20.04.4 LTS
in my terminal i see this output:
/GIT/project$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
/GIT/project$ cd scripts/
/GIT/project/scripts$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
/GIT/project/scripts$ docker-compose ps
Name Command State Ports
-----------------------------------------------------------------------------------------------------
scripts_db_1 docker-entrypoint.sh --def ... Up 0.0.0.0:3306->3306/tcp,:::3306->3306/tcp,
33060/tcp
/GIT/project/scripts$
docker-compose.yaml
version: '3.3'
services:
db:
image: mysql:5.7
# NOTE: use of "mysql_native_password" is not recommended: https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password
# (this is just an example, not intended to be a production configuration)
command: --default-authentication-plugin=mysql_native_password
restart: always
ports:
# <Port exposed> : < MySQL Port running inside container>
- 3306:3306
expose:
# Opens port 3306 on the container
- 3306
# Where our data will be persisted
volumes:
- treip:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: changeit
MYSQL_DATABASE: treip
volumes:
treip:
I executed the container with sudo and the problem was solve. now the container apear using docker ps, so instead of docker-compose up I executed it with sudo sudo docker-compose up . Sorry, my bad.
I am setting up a NGINX node as container using docker compose file.
my compose file as below:
version: '3.9'
services:
reverse_proxy_nginx:
image: nginx:1.19.10-alpine
container_name: reverse_proxy_nginx
networks:
external_net:
ipv4_address: 192.168.100.10
ports:
- "80:80"
volumes:
- ./static/:/usr/share/nginx/html/
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- /etc/localtime:/etc/localtime:ro
command: sh -c "rm -f /etc/nginx/conf.d/* &&
nginx -c /etc/nginx/nginx.conf"
tty: true
networks:
external_net:
external:
name: localsw
after docker-compose up command:
[root#Site Reverse_Proxy]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e1498798339d nginx:1.19.10-alpine "/docker-entrypoint.…" 6 seconds ago **Exited (0) 5 seconds ago** reverse_proxy_nginx
"docker logs" command and -json.log all output nothing !!
[root#Site Reverse_Proxy]# docker logs reverse_proxy_nginx
[root#Site Reverse_Proxy]# cat /var/lib/docker/containers/e1498798339d022ec5d744e1c557ca3e9f0779be114ffb0349acc9be1a70e5c7/e1498798339d022ec5d744e1c557ca3e9f0779be114ffb0349acc9be1a70e5c7-json.log
[root#Site Reverse_Proxy]#
In my previous attempts, I did see "docker logs" output logs showing executing docker-entrypoint.sh and other shell scripts (10-listen-on-ipv6-by-default.sh, 20-envsubst-on-templates.sh etc), also looking for default.conf file to initialize NGINX server. but now, it outputs nothing !!
I searched quite a long time on this issue, and did not find any solid & holistic solution yet. anyone knows where I should report this bug please ?
put below directive in config file solves the problem.
daemon off;
I have a very basic node/express app with a dockerfile and a docker-compose file. When I run the docker container using
docker run -p 3000:3000 service:0.0.1 npm run dev
I can go to localhost:3000 and see my service. However, when I do:
docker-compose run server npm run dev
I can't see anything on localhost:3000, below are my files:
Dockerfile
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
EXPOSE 3000
docker-compose.yml
version: "3.7"
services:
server:
build: .
ports:
- "3000:3000"
image: service:0.0.1
environment:
- LOGLEVEL=debug
depends_on:
- db
db:
container_name: "website_service__db"
image: postgres
environment:
- POSTGRES_USER=user
- POSTGRES_PASSWORD=pass
- POSTGRES_DB=website_service
also, everything is working fine from the terminal/docker side - no errors and services are running fine, i just cant access the node endpoints
tl;dr
docker-compose run --service-ports server npm run dev
// the part that changed is the new '--service-ports' argument
the issue was a missing docker-compose run argument --service-ports:
from these docs:
The second difference is that the docker-compose run command does not create any of the ports specified in the service configuration. This prevents port collisions with already-open ports. If you do want the service’s ports to be created and mapped to the host, specify the --service-ports flag:
I am using ansible (2.0) docker module to start a jboss docker container. My playbook looks as follows:
- name: Pull aplication jboss container
docker:
name: jboss
image: jboss/wildfly
state: started
pull: always
ports:
- "9990:9990"
- "8080:8080"
command: "/opt/jboss/wildfly/bin/standalone.sh -b 0.0.0.0 -bmanagement 0.0.0.0"
I want to mimic the command shown in the docs:
docker run -p 8080:8080 -p 9990:9990 -it jboss/wildfly /opt/jboss/wildfly/bin/standalone.sh -b 0.0.0.0 -bmanagement 0.0.0.0
If I execute the playbook, and run docker ps, my ports are not bound to 9990, only 8080:
0.0.0.0:8080->8080/tcp
If I do not use the playbook, and only run my docker container using the aforementioned command that I want to mimic, I can see both ports:
0.0.0.0:8080->8080/tcp, 0.0.0.0:9990->9990/tcp
How would I use the docker module to bind both 8080 and 9990 ports?
I ended up manually exposing the both ports to make this work, via the expose command:
- name: Pull aplication jboss container
docker:
name: jboss
image: jboss/wildfly
state: started
pull: always
expose:
- 9990
- 8080
ports:
- "9990:9990"
- "8080:8080"
command: "/opt/jboss/wildfly/bin/standalone.sh -b 0.0.0.0 -bmanagement 0.0.0.0"
I am not sure if that is the best answer, but for now, it is solving the problem of the ports not being exposed.
/usr/local/bin/docker-compose up
I am using this command on Amazon Linux. It does not bind the ports, so I could not connect to the services running inside the container. The same configuration is working on a local development server. Not sure what I am missing.
[root#ip-10-0-1-42 ec2-user]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ec6320747ef3 d8bd4345ca7f "/bin/sh -c 'gulp bu…" 30 seconds ago Up 30 seconds vigilant_jackson
Here is the docker-compose.yml:
version: '2'
services:
web:
build: .
command: gulp serve
env_file:
- .env
volumes:
- .:/app/code
ports:
- "8050:8000"
- "8005:8005"
- "8888:8888"
npm -v 5.6.0
docker -v Docker version 18.06.1-ce, build e68fc7a215d7133c34aa18e3b72b4a21fd0c6136
Are you sure the ports are not published?
Use docker inspect, I would guess that they are published. If this is the case, then my guess is that as you are on AWS, you are not ssh-ing to the opened port (8050, 8005, 8888 are ports of the AWS linux instance, if I got your question correctly).