docker-compose up doesn't map ports on centos 7 - docker

I'm trying to docker-compose an existing application. Now I struggle on centos on a basic task.
Given docker-compose.yml:
version: '3.8'
services:
nginx:
image: nginx:latest
ports:
- "1024:80"
When run with docker-compose up localhost:1024 is not accessible. When I add the started container to the default bridge network (docker network connect <id of bridge> <id of container>), localhost:1024 is accessible.
When run with docker run -p 1024:80 nginx:latest localhost:1024 is accessible.
docker-compose version 1.26.2, build eefe0d31
Docker version 19.03.12, build 48a66213fe
CentOS Linux release 7.6.1810
When attempting to docker-compose up the same file on macOS localhost:1024 is accessible.
EDIT #1
docker ps PORTS output: 0.0.0.0:1024->80/tcp
new interface added ifconfig: br-da0abb61196d
Same behavior on different ports e.g. 8080

Related

Why container based on ubuntu didn't run from docker-compose file, when that work for similar nginx container? [duplicate]

This question already has answers here:
Ubuntu container keep restarting
(1 answer)
How can I run bash in a new container of a docker image?
(1 answer)
Docker compose detached mode not working
(2 answers)
Closed 1 year ago.
I try to run docker container using docker-compose file instead of a long command line.
I want to run docker-compose file based on ubuntu:latest. Container created but can't run.
version: "3.9"
services:
ubuntu:
image: ubuntu:latest
container_name: nginx_from_scratch3
ports:
- "80:80"
But before I've tried add in my docker-compose file line
command: bash
And noting change. I think what after running container continue to work. But that didn't happend.
But on the other side if I use nginx image all run perfectly.
version: "3.9"
services:
nginx1:
image: nginx
container_name: nginx_from_scratch4
ports:
- "80:80"
Why docker-compose file for nginx image work, and doesn’t work for ubuntu image.
Docker container exits if task inside is done. So when you run nginx, it starts nginx automatically and keep it alive. As for ubuntu, there's no any task to keep running and container ended immediately. So if you want to keep it alive even if it does not have any job: add tail -f, like this:
version: "3.9"
services:
ubuntu:
image: ubuntu
command: tail -F anything
After you do docker container ps you will see it running.
And you can move to it with
docker exec -it container_name bash

Links working with `docker-compose` but not `docker compose`

I have been using a docker compose file to run a development environment for a microservices architecture that in production is deployed to kubernetes, so I use links to map k8s provided domain names to the compose service names. e.g
links:
- "kafka:kafkadc-c44b-44.default.svc.cluster.local"
All works well when using docker-compose. But when using the new docker compose (note no hyphen), the containers are unable to comminicate with eachother. Kafka connections fail. HTTP requests fail.
Are there any changes between the docker cli version of compose, and the old docker-compose command. I cann't see a version of docker compose without the hypen, but with I have the following version information:
docker-compose version 1.29.0, build 07737305
docker-py version: 5.0.0
CPython version: 3.9.0
OpenSSL version: OpenSSL 1.1.1h 22 Sep 2020
You can use hostname to specify a hostname for the container within its network or you can use an alias if you need a hostname per network.
e.g.
db:
image: mysql:5.7
container_name: mycontainername
hostname: myhostname
networks:
default:
aliases:
myalias

Running a ubuntu container in background using docker compose

I am able to run a docker container using following docker command:
docker run -it ubuntu /bin/bash
Now I am trying to do it by using docker-compose:
version: "3"
services:
ubuntu:
container_name: ubuntu
image: ubuntu
restart: on-failure
command: "/bin/bash"
Now when I do :
docker-compose up -d
Can see docker container starting and exiting immediately.
I tried looking at the logs :
docker logs b8 //b8 is container id
But there are no error logs.
How do I keep ubuntu container running in background using docker.
( I am using docker on windows , linux version)
This is normal.
You are starting an ubuntu container with bash as the command (thus the root process). The thing is to keep bash alive you need to attach it with a terminal. This is why when you want to get a bash in a container, you're using -ti with your command :
docker container exec -ti [my_container_id] bash
So if you want to keep your ubuntu container alive and don't want to attach it to a terminal, you'll have to use a process that will stay alive for as long as you want.
Below is an example with sleep infinity as your main process
version: "3"
services:
ubuntu:
container_name: ubuntu
image: ubuntu
restart: on-failure
command: ["sleep","infinity"]
With this example, you container will stay running indefinitely.

Volume data does not fill when running a bamboo container on the server

I am trying to run bamboo on server using docker containers. When i running on local machine work normally and volume save datas successfully. But when i run same docker compose file on server, volume data not save my datas.
docker-compose.yml
version: '3.2'
services:
bamboo:
container_name: bamboo-server_test
image: atlassian/bamboo-server
volumes:
- ./volumes/bamboo_test_vol:/var/atlassian/application-data/bamboo
ports:
- 8085:8085
volumes:
bamboo_test_vol:
Run this compose file on local machine
$ docker-compose up -d
Creating network "test_default" with the default driver
Creating volume "test_bamboo_test_vol" with default driver
Creating bamboo-server_test ... done
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
916c98ca1a9d atlassian/bamboo-server "/entrypoint.sh" 24 minutes ago Up 24 minutes 0.0.0.0:8085->8085/tcp, 54663/tcp bamboo-server_test
$ ls
docker-compose.yml volumes
$ cd volumes/bamboo_test_vol/
$ ls
bamboo.cfg.xml logs
localhost:8085
Run this compose file on server
$ ssh <name>#<ip_address>
password for <name>:
$ docker-compose up -d
Creating network "test_default" with the default driver
Creating volume "test_bamboo_test_vol" with default driver
Creating bamboo-server_test ... done
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
38b77e1b736f atlassian/bamboo-server "/entrypoint.sh" 12 seconds ago Up 11 seconds 0.0.0.0:8085->8085/tcp, 54663/tcp bamboo-server_test
$ ls
docker-compose.yml volumes
$ cd volumes/
$ cd bamboo_test_vol/
$ ls
$ # VOLUME PATH IS EMPTY
server_ip:8085
I didn't have this problem when I tried the same process for jira-software. Why can't it work through the bamboo server even though I use the exact same compose file?
I had the same problem when I wanted to upgrade my Bamboo server instance with my mounted host volume for the bamboo-home directory.
The following was in my docker-compose file:
version: '2.2'
bamboo-server:
image: atlassian/bamboo-server:${BAMBOO_VERSION}
container_name: bamboo-server
environment:
TZ: 'Europe/Berlin'
restart: always
init: true
volumes:
- ./bamboo/bamboo-server/data:/var/atlassian/application-data/bamboo
ports:
- "8085:8085"
- "54663:54663"
When i started with docker-compose up -d bamboo-server, the container never took the files from the host system. So I tried it first without docker-compose, following the instructions of Atlassian Bamboo with the following command:
docker run -v ./bamboo/bamboo-server/data:/var/atlassian/application-data/bamboo --name="bamboo-server" --init -d -p 54663:54663 -p 8085:8085 atlassian/bamboo-server:${BAMBOO_VERSION}
The following error message was displayed:
docker: Error response from daemon: create ./bamboo/bamboo-server/data: "./bamboo/bamboo-server/data" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path.
So I converted the error message and took the absolute path:
docker run -v /var/project/bamboo/bamboo-server/data:/var/atlassian/application-data/bamboo --name="bamboo-server" --init -d -p 54663:54663 -p 8085:8085 atlassian/bamboo-server:${BAMBOO_VERSION}
After the successful start, I switched to the docker container via SSH and all files were as usual in the docker directory.
I transferred the whole thing to the docker-compose file and took the absolute path in the volumes section. Subsequently it also worked with the docker-compose file.
My docker-compose file then looked like this:
[...]
init: true
volumes:
- /var/project/bamboo/bamboo-server/data:/var/atlassian/application-data/bamboo
ports:
[...]
Setting up a containerized Bamboo Server is not supported for these reasons;
Repository-stored Specs (RSS) are no longer processed in Docker by default. Running RSS in Docker was not possible because;
there is no Docker capability added on the Bamboo server by default,
the setup would require running Docker in Docker.

I want to run a docker-compose.yml on a remote docker daemon, what about volumes?

I want to run docker-compose up on a remote docker daemon:
DOCKER_HOST=tcp://...:2375 docker-compose up
In docker-compose.yml, I have a volume binding to a local file:
version: "3"
services:
nginx:
image: nginx:latest
ports:
- 80:80
volumes:
- ./etc/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
This won't work, as the remote docker daemon will be unable to locate ./etc/nginx/nginx.conf.
What is the best approach to handle this?
Extend the existing docker image by creating your own docker image.
Ref : How to extend existing docker container?
Copy the relevant files (from docker build-context) to appropriate directory and then it will be available in docker image and hence will also be available in remote docker demon as well.

Resources