I am running a docker container via docker-compose. Here is the image I am using.
On that page link above, there's a section 'Give the user root permissions (add to sudoers)' with an example:
docker run -d -p 8787:8787 -e ROOT=TRUE -e PASSWORD=yourpasswordhere rocker/rstudio
My question is, how can I use this ROOT=TRUE configuration within docker compose?
Tried:
version: "3.5"
services:
server:
image: 123456.blah.dogs.us-east-1.amazonaws.com/ds/rstudio-image/main:latest
ports:
- 8787:8787
environment:
PASSWORD: test
root: 'TRUE'
When I try to run this I get:
docker-compose up
ERROR: The Compose file './docker-compose.yaml' is invalid because:
Unsupported config option for services.server: 'root'
How can I add the configuration ROOT=TRUE via docker-compose when running this image as a container?
Related
In a docker-compose.yml file I have defined the following service:
php:
container_name: php
build:
context: ./container/php
dockerfile: Dockerfile
networks:
- saasnet
volumes:
- ./services:/var/www/html
- ./logs/php:/usr/local/etc/php-fpm.d/zz-log.conf
environment:
- "DB_PORT=3306"
- "DB_HOST=database"
It all builds fine, and another service (nginx) using the same volume mapping, - ./services:/var/www/html finds php as expected, so it all works in the browser. So far, so good.
But now I want to go into the container because I want to run composer install from a certain directory inside the container. So I go into the container using:
docker run -it php bash
And I find myself in the container at /var/www/html, where I expect to be able to navigate as if I were on my host machine in ./services directory, but ls at this point inside the container shows no files at all.
What am I missing or not understanding about how this works?
Your problem is that your are not specifying the volume on your run command - docker run is not aware of your docker-compose.yml. If you want to run it with all your options as specifiend in it, you need to either use docker-compose run, or pass all options to docker run:
docker-compose run php bash
docker run -it -e B_PORT=3306 -e DB_HOST=database -v ./services:/var/www/html -v ./logs/php:/usr/local/etc/php-fpm.d/zz-log.conf php bash
Let's say I have a couple of services web1 and web2 and I can spin them up in prod or dev
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
Now let's say I do the same for a testing config. If my test yml were only changing the container name, for example,
version: '3.6'
services:
web1:
container_name: web1_test
web2:
container_name: web2_test
and I had my web services already running, then this would recreate the services, effectively replacing their containers with new ones bearing the new config (in this case a new name). But I'd rather not, it'd be nice to just spin them up and down without interfering with the originals.
A better experience would be
version: '3.6'
services:
web1:
service_name: web1_test
web2:
service_name: web2_test
then I could start the test versions and stop them without touching the originals.
docker-compose -f docker-compose.yml -f docker-compose.test.yml up -d web1_test web2_test
Is there any way to leave the original services up and spin up some new test instances with a simple config overlay?
Note: I'm currently using docker-compose run to meet my needs. In practice I'm also modifying env variables and ports likes so:
docker-compose -f Docker/docker-compose.yml -f Docker/docker-compose.dev.yml run -d --name web1_test -e VAR1=web1_test_var -p 5001:5000 web1
so I already know 'how to get it done', I'm looking more for, am I missing a better way to accomplish the same? It'd be nice to have the port and env and name stuff in a config wouldn't it?
Instead of using container_name per service you could use different project names for the same docker-compose.yml using the flag: -p, --project-name NAME.
docker-compose -f docker-compose.yml -p foo up -d
foo_web_1
foo_web_2
docker-compose -f docker-compose.yml -p bar up -d
bar_web_1
bar_web_2
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'm using docker for php and another one for sql. Also I have a makefile to run commands in a instance of this container. This is the entry I use for command execution, and I would like to use sql container I have.
command:
docker run --rm \
--volume=${PWD}/code:/code \
--volume=${PWD}/json:/json:rw \
--volume=${PWD}/file:/file:rw \
own_php:latest \
time php /code/public/index_hex.php ${page}
If I try to execute this command from the make file, I get the following error.
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed:
Name does not resolve
This is the docker-compose I have in my project
version: '3'
services:
sql:
image: mariadb
ports:
- "3307:3306"
environment:
MYSQL_ROOT_PASSWORD: root
volumes:
- ./init-db:/docker-entrypoint-initdb.d
- ./.mysql-data:/var/lib/mysql/
crawler:
build:
context: './docker-base'
depends_on:
- sql
volumes:
- ./json:/json:rw
- ./file:/file:rw
- ./code:/code
But if I run the container using my docker-composer, and I enter inside the container the command executes well.
It is possible for docker run --rm to use another container?
Docker Compose creates a network for each compose file and you have to attach your manually docker run container to that network to be able to reach other containers on it. The network will usually be named something like directoryname_default, based on the name of the directory holding the compose file, and it will show up in the docker network ls listing.
You should run something like
docker run --rm --net directoryname_default ...
I have several arguments in my docker run command like
docker run --rm -v /apps/hastebin/data:/app/data --name hastebin -d -p 7777:7777 -e STORAGE_TYPE=file rlister/hastebin
Can I put all the arguments of this in a default/config file so that I dont have to mention it explicitly in the run command?
You can try docker compose
With Compose, you use a Compose file to configure your application’s services. Then, using a single command, you create and start all the services from your configuration
In your case docker-compose.yml file will looks like
version: '2'
services:
hastebin:
image: rlister/hastebin
ports:
- "7777:7777"
volumes:
- /apps/hastebin/data:/app/data
environment:
- STORAGE_TYPE=file
And you can run service by command docker-compose up