how do i run commands/open-terminal inside Parse standalone container - docker

I'm running a container of the official docker image parseplatform/parse-server :
tried the following but "bash" is not recognized:
docker exec -i -t container_name bash

use:
sudo docker exec -i -t container_name sh

Related

while starting a docker container I have to execute a script inside docker container

while starting a docker container I have to execute a script inside docker container. Can I do it using docker run command or docker start command mentioning the path in docker? I know I have to use CMD in docker file but dockerfile is not present
Have you tried
docker run -it <image-name> bash "command-to-execute"
To enter a running Docker container (get a Bash prompt inside the container), please run the following:
docker container exec -it <container_id> /bin/bash
You can get the container_id by listing running Docker containers with:
docker container ps -a or docker ps -a
docker run --name TEST -d image sh -c " CMD "
in CMD section you can give the path of shell script

How to check mysql version inside mysql docker container

Is it possible to check it without getting inside the container?
something like
docker container exec -it <container name> ....
You can check the version using Docker inspect.
docker inspect mysql8 | grep MYSQL_MAJOR
#Or to print version plus major both
docker inspect mysql8 | grep MYSQL_
or without running the container
docker run -it mysql8 bash -c "printenv | grep MYSQL_VERSION"
Or if the container is already running
docker exec mysql bash -c "mysql -V"
You can use exec to run commands against a container:
docker exec -it <container_name> bash -c "mysql -V"
get Container ID:
docker ps
Ex image: enter image description here
Remote to docker & using bash in it:
docker exec -it <container_name> bash
Input command:
mysql -V

How can I execute command inside a Docker container from a Composer image?

I am using docker run --rm -it -v $(pwd):/app composer/composer:1.1-alpine install. But, I need to execute some Bash codes before that, how can I achieve that?
You can enter a running container by running the command:
docker exec -it <container-name> sh

How to take Oracle-xe-11g backup from running Docker container

I am running oracle-xe-11g on rancher os. I want to take the data backup of my DB. When I tried with the command
docker exec -it $Container_Name /bin/bash
then I entered:
exp userid=username/password file=test.dmp
It is working fine, and it created the test.dump file.
But I want to run the command with the docker exec command itself. When I tried this command:
docker exec $Container_Name sh -C exp userid=username/password file=test.dmp
I am getting this error message: sh: 0: Can't open exp.
The problem is:
When running bash with -c switch it is not running as interactive or a login shell so bash won't read the same startup scripts. Anything set in /etc/profile, ~/.bash_profile, ~/.bash_login, or ~/.profile would be skipped.
Workaround:
run your container with following command:
sudo docker run -d --name Oracle-DB -p 49160:22 -p 1521:1521 -e ORACLE_ALLOW_REMOTE=true -e ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe -e PATH=/u01/app/oracle/product/11.2.0/xe/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin -e ORACLE_SID=XE -e SHLVL=1 wnameless/oracle-xe-11g
What I'm doing is specifying the environment variables set in the container using docker.
Now for generating the backup file:
sudo docker exec -it e0e6a0d3e6a9 /bin/bash -c "exp userid=system/oracle file=/test.dmp"
Please note the file will be created inside the container, so you need to copy it to docker host via docker cp command
This is how I did it. Mount a volume to the container e.g. /share/backups/ then execute:
docker exec -it oracle /bin/bash -c "ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe ORACLE_SID=XE /u01/app/oracle/product/11.2.0/xe/bin/exp userid=<username>/<password> owner=<owner> file=/share/backups/$(date +"%Y%m%d")_backup.dmp"

Running a script in docker container and not killing the script when leaving terminal

I have got some docker container for instance my_container
I Want to run a long living script in my container, but not killing it while leaving the shell
I would like to do something like that
docker exec -ti my_container /bin/bash
And then
screen -S myScreen
Then
Executing my script in screen and exit the terminal
Unfortunately, I cannot execute screen in docker terminal
this maybe help you.
docker exec -i -t c2ab7ae71ab8 sh -c "exec >/dev/tty 2>/dev/tty </dev/tty && /usr/bin/screen -r nmsrv -s /bin/bash"
and this is the reference link
Only way I can think of is to run your container with your script at the start;
docker run -d --name my_container nginx /etc/init.d/myscript
If you have to run the script directly in an already running container, you can do that with exec:
docker exec my_container /path/to/some_script.sh
or if you wanna run it through Php:
docker exec my_container php /path/to/some_script.php
That said, you typically don't want to run scripts in already running containers, but to just use the same image as some already running container. You can do that with a standard docker run:
docker run -a stdout --rm some_repo/some_image:some_tag php /path/to/some_script.php

Resources