Run jhipster-registry in production - docker

This is a continuation of my previous question about running a jhipster microservices application on AWS.
I've used docker-machine to create a new VM with Docker installed.
I have setup docker registry, and pushed my images to it, as well as logged into this registry on the AWS-VM.
I attempted to copy the contents of the /docker-composer directory I generated using yo jhipster:docker-compose and attempted to run:
docker-compose up -d
But I receive the error:
ubuntu#aws-test:~/docker-compose$ sudo docker-compose up
Unsupported config option for services service: 'jhipster-registry'
I can manually run the jhipster-registry with docker, but as there are many other underlying services I'd prefer to create a production docker-compose.yml file.

It looks like you're using an older version of docker-compose that doesn't support the V2 format. You need to upgrade to at least 1.6.2 (but 1.7.0 is currently the latest).

Aside of your docker-compose.yml you should have the jhipster-registry.yml and the elk.yml files, if one of those files are not present it won't work because the docker-compose file is looking for those files.
If you want to have all in one file you have to copy the jhipster-registry service in jhipster-registry.yml into your docker-compose.yml.

Related

docker-compose transition from docker run

I have already created containers running in my server.
They were created through the command line with docker run.
I believe using docker-compose will result in a more portable containers (I don't need to docker run all containers in a different server, only put the same file).
Is there a way to translate the already created containers to a docker-compose file?
In their website (https://docs.docker.com/compose/gettingstarted/), it is mentioned to use docker-compose migrate_to_labels, but it seems the command is not working in the latest version of docker-compose

Docker setup but apache on local machine

I have a docker setup (php7,mysql and apache). This is working correctly.
However, I have to transfer the project on the server where there is already an apache running.
I was wondering how I could use the apache on the server to connect to my docker setup.
You can use either docker-compose or Dockerfile, or combination of both to use together.
You can read more about them in Docker Compose Docs and Dockerfile Docs.
In Simple Answer:
Create a docker-compose.yml file with contents you need as per above docs with a Dockerfile.
You should connect them together in your code by modifying files, like instead of localhost for database host, you should change it to the name you specify in docker-compose.yml file.
Also copying or adding some files in apache, like /etc/apache2/httpd.conf and /etc/apache2/sites-available/*.conf (all files ending with conf), and for mysql like /var/lib/mysql/ directory (database files), and of course your project files.
Then run docker-compose up -d command.

Docker device path differs depending on commands

After recent Docker update (Docker Desktop for Mac) my stack broke.
I'm using my docker-compose config in two ways - with up command and with run command to execute some operations via containers (when it's not up yet).
I'm getting error:
ERROR: Configuration for volume my_code specifies "device" driver_opt /Users/me/Projects/project/backend/my_code, but a volume with the same name uses a different "device" driver_opt (/host_mnt/Users/me/Projects/project/backend/my_code). If you wish to use the new configuration, please remove the existing volume "my_code" first:
I have configured docker-compose with volumes shared between containers.
volumes:
my_code:
driver: local
driver_opts:
type: none
device: ${PWD}/project/backend/my_code
o: bind
Looks like for some reason up and run commands get's different path from $PWD in docker-compose. One get's prefixed with /host_mnt and the other doesn't. Is this a bug or maybe my config is invalid?
Docker for Mac 2.4.0.0 stable
Docker Compose 1.27.4
Catalina
I just had the same issue with the prefix /host_mnt on a Ubuntu system.
This is something related to Docker Desktop.
The solution for me was to uninstall docker and Docker desktop according to the documentation
https://docs.docker.com/desktop/install/ubuntu/
https://docs.docker.com/engine/install/ubuntu/
And afterwards also delete the docker config files manually.
rm -rf ~/.docker
Then I just installed the docker engine instead of the docker desktop.
The problem was caused by an update on Docker Desktop that adds that /host_mnt prefix for compatibility with Windows users.

docker-compose build and up

I am not an advance user so please bear with me.
I am building a docker image using docker-compose -f mydocker-compose-file.yml ... on my machine.
The image then been pushed to a remote docker registry.
Then from a remote server I pull down this image.
To run this image; I have to copy mydocker-compose-file.yml from my machine to remote server and then run docker-compose -f mydocker-compose-file.yml up -d.
I find this very inefficient as why I need the same YAML file to run the docker image (should I?).
Is there a way to just spin up the container without this file from remote machine?
As of compose 1.24 along with the 18.09 release of docker (you'll need at least that client version on the remote host), you can run docker commands to a remote host over SSH.
# all docker commands in this shell will not talk to the remote host
export DOCKER_HOST=ssh://user#host
# you can verify that with docker info to see which engine you're talking to
docker info
# and now run your docker-compose up command locally to start/stop containers
docker-compose up -d
With previous versions, you could configure TLS certificates to allow specific clients to connect to the docker API over a network connection. See these docs for more details.
Note, if you have host volumes, the variables and paths will be expanded to your laptop directories, but the host mounts will happen on the remote server where those directories may not exist. This is a good situation to switch to named volumes.
Everything you can do with Docker Compose, you can do with plain docker commands.
Depending on how exactly you're interacting with the remote server, your tooling might have native ways to do this. One specific example I'm familiar with is the Ansible docker_container module. If you're already using a tool like Ansible, Chef, or Salt, you can probably use a tool like this to do the same thing your docker-compose.yml file does.
But otherwise there's more or less a direct translation between a docker-compose.yml file
version: '3'
services:
foo:
image: me/foo:20190510.01
ports: ['8080:8080']
and a command line
docker run -d --name foo -p 8080:8080 me/foo:20190510.01
My experience has been that the docker run commands quickly become unwieldy and you want to record them in a file; and once they're in a file, you start to wish they were in a more structured format, even if you need an auxiliary tool to run them; which brings you back to copying around the docker-compose.yml file. I think that's pretty routine. (Something needs to tell the server what to run.)

Can I run more than one services with docker-compose in one command?

I have read https://docs.docker.com/compose/reference/run/, and I found that I can run a single service like web service here:
docker-compose run web
Can I run in a single line two or more services like this?
docker-compose run web, backup
Currently docker-compose run does not allow specifying multiple services, and there aren't any plans to do so either due to the way docker-compose run is designed.
There are other ways to achieve a similar result:
Use the depends_on directive to specify that the web service depends on the backup service (or vice versa). It may be useful to create a new docker-compose file for this.
Use docker-compose up web backup instead of docker-compose run
Run it in separate commands like docker-compose run web and docker-compose run backup in another shell.
Merge the web and backup services into a single service in your docker-compose.yml.
Version docker-compose version 1.29.2, build 5becea4c allows it using the sintax below:
docker-compose up -d SERVICE1 SERVICE2
It may be more convenient for you to use profiles.

Resources