Is there any way to run docker with multiple command? - docker

My command is here:
sudo docker run --name ws_was_con -itd --net=host -p 8022:8022 --restart always account_some/project_some:latest cd /project_directory && daphne -b 0.0.0.0 -p 8022 project_some.asgi:application
but it returns:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "cd": executable file not found in $PATH: unknown.
I have to run with that command cd /project_directory && daphne -b 0.0.0.0 -p 8022 project_some.asgi:application without CMD on Dockerfile
How can I do that?

Try: docker run ... sh -c 'cd /project_directory; daphne -b 0.0.0.0 -p 8022 project_some.asgi:application'

You need to provide something to execute your command.
docker run <...> account_some/project_some:latest /bin/bash cd <path>

If you're just trying to run a command in a non-default directory, docker run has a -w option to specify the working directory; you don't need a cd command.
sudo docker run -d \
--name ws_was_con \
-p 8022:8022 \
--restart always \
-w /projectdirectory \ # <== add this line
account_some/project_some:latest \
daphne -b 0.0.0.0 -p 8022 project_some.asgi:application
In practice, though, it's better to put these settings in your image's Dockerfile, so that you don't have to repeat them every time you run the application.
# in the Dockerfile
WORKDIR /projectdirectory
EXPOSE 8022 # technically does nothing but good practice anyways
CMD daphne -b 0.0.0.0 -p 8022 project_some.asgi:application
sudo docker run -d --name ws_was_con -p 8022:8022 --restart always \
account_some/project_some:latest
# without the -w option or a command override

Related

podman not running container in quay setup in centos9

I am setting up quay in a vm with centos distro. This is the guide I am following: quay deploy guide
once I install Podman I am trying to run first container with below command:
I set up this env variable:
export QUAY=QUAY
and made a dir of same name in home:
mkdir QUAY
once I install Podman I am trying to run first container with below command:
$ sudo podman run -d --rm --name postgresql-quay \
-e POSTGRESQL_USER=quayuser \
-e POSTGRESQL_PASSWORD=quaypass \
-e POSTGRESQL_DATABASE=quay \
-e POSTGRESQL_ADMIN_PASSWORD=adminpass \
-p 5432:5432 \
-v $QUAY/postgres-quay:/var/lib/pgsql/data:Z \
registry.redhat.io/rhel8/postgresql-10:1
and I am getting following error:
sudo podman run -d --rm --name postgresql-quay -e POSTGRESQL_USER=quayuser -e POSTGRESQL_PASSWORD=quaypass -e POSTGRESQL_DATABASE=quay -e POSTGRESQL_ADMIN_PASSWORD=adminpass -p 5432:5432 -v QUAY/postgres-quay:/var/lib/pgsql/data:Z registry.redhat.io/rhel8/postgresql-10:1
Error: error creating named volume "QUAY/postgres-quay": error running volume create option: names must match [a-zA-Z0-9][a-zA-Z0-9_.-]*: invalid argument
The bind mount needs to be specified as an absolute path or a relative path that starts with ./ or ../.
In other words instead of
-v QUAY/postgres-quay:/var/lib/pgsql/data:Z
use
-v ./QUAY/postgres-quay:/var/lib/pgsql/data:Z
(I replaced $QUAY with its value QUAY)

How to mount data directory?

I am not able to start percona mysql dockerized instance if I try to mount the data directory like this:
docker run --name percona57f -p 3384:3306 -v /my/custom3384:/etc/mysql/conf.d -v /storage/data3384:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=india3384 -e INIT_TOKUDB=1 -d percona/percona-server:5.7
The error is as shown below:
[ERROR] --initialize specified but the data directory exists and is not writable. Aborting.
[ERROR] Aborting
The command will work if I do not include the data directory like this...
docker run --name percona57g -p 3384:3306 -v /my/custom3384:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=india3384 -e INIT_TOKUDB=1 -d percona/percona-server:5.7
But it is very important for me to mount the data directory on host machine. Any way to enable this -v /storage/data3384:/var/lib/mysql
Run this command before docker run:
chown 1001 /my/custom3384
This is the UID for the mysql user, as shown in the Dockerfile for the percona image:
https://github.com/percona/percona-docker/blob/master/percona-server/Dockerfile
RUN useradd -u 1001 -r -g 0 -s /sbin/nologin \
-c "Default Application User" mysql

How to launch the Solr techproducts example on Docker?

I am running solr in docker and I tried the commands from the comment.
docker run --name test -d -p 8983:8983 -t solr
docker exec -it --user=solr test bin/solr create -c techproducts -d sample_techproducts_configs
After the last command, I received the following error message:
Unrecognized argument: example/exampledocs/*.xml .
If this was intended to be a data file, it does not exist relative to /opt/solr
Is this the correct location for the techproducts.xml data?
I looked at the official solr image on hub.docker.com and I found this,
docker run -d -P -v $PWD/myconfig:/myconfig solr solr-create -c mycore -d /myconfig
I guess you need to pass in core configuration from your host with bind mount as in the example. In this case it is not myconfig, it is "sample_techproducts_configs"
I tried the following, it worked for me.
docker run --name my_solr -d -p 8983:8983 -t solr
docker exec -it --user=solr my_solr bin/solr create_core -c
techproducts
docker exec -it --user=solr my_solr bin/post -c techproducts
example/exampledocs/

convert docker run to docker-compose.yml special args

I have the folllowing commands that I need to convert to docker-compose
docker run \
-p 993:993 \
-p 587:587 \
-v /home/vmail:/home/vmail \
-e MAILNAME="somedomain.com"
-v /etc/postfix
-v /etc/dovecot
-v /etc/ssl
-v /etc/opendkim
-v /var/log/container:/var/log
email
--email youremail#somedomain.com
How do I pass the --email arg to the ENTRYPOINT using docker-compose?
Docker compose has an entrypoint property which you can use.
...
entrypoint:
-email=youremail#somedomain.com
You could use
command: my_app --email youremail#somedomain.com
I need the same thing, actually how to map ports in compose like docker run -p provides. I still want to use the docker-compose up to start tho.
I think the ports option on docs page is the answer.
Add this to your compose yaml file:
ports:
- "127.0.0.1:<host-port>:<container-port>"

Docker user permission while mounting a directory

I am using the following Dockerfile to build Solr using Docker.
FROM solr:5.5
ENV SOLR_HOME=/opt/solr/server/solr/cores
RUN mkdir ${SOLR_HOME}
RUN chown -R solr:solr ${SOLR_HOME}
VOLUME ["${SOLR_HOME}"]
EXPOSE 8983
I try to run the following Docker command to mount a host directory to the container:
docker run --restart=always -d --name solr-demo \
--privileged=true -p 8983:8983 \
-v /data/solr_demo:/opt/solr/server/solr/cores \
solr-test:latest
I am also copying the required solr.xml file into the data/solr_demo. When I run the docker run command I get the following error:
stat: cannot stat ‘/opt/solr/server/solr/cores’: No such file or directory 42146d74b446ba4784fd197688e3210f294aad8755ae730cc559132720bcc35a
Error response from daemon: Container 42146d74b446ba4784fd197688e3210f294aad8755ae730cc559132720bcc35a is restarting, wait until the container is running
From your comment, it appears you're mounting a nonexistent directory for your volume. Try this command that mounts /data/solr_demo1 instead of /data/solr_demo as your volume.
docker run --restart=always -d --name solr-demo \
--privileged=true -p 8983:8983 \
-v /data/solr_demo1:/opt/solr/server/solr/cores \
solr-test:latest
If it is really an user problem (it remind me of some issue I add with apache in container), you should consider using Gosu. https://github.com/tianon/gosu
It will let you run and swap user correctly and have a nice mapping from your local users and users inside the container.
Hope it will be useful.

Resources