How to use list in "docker's run -e options"? - docker

I downloaded my spring boot project from git on Amazon Linux2 OS and made it a docker image.
Then, I tried to use the "docker run" command to run the docker container with this image.
At this time, there are values in the form of an array among the environmental variables I need, and other "docker run options" worked well, but there was a problem with the values in this form of an array.
// Command 1
docker run -itd --name example_container -e DDL_AUTO={update,create,validate} -p 80:8080 example_image
In command 1's case, docker: invalid reference format: repository name must be lowercase. error occured.
// Command 2 (put space between update, create, validate)
docker run -itd --name example_container -e DDL_AUTO={update, create, validate} -p 80:8080 example_image
In command 2's case, docker: invalid reference format. error occured.
Is there a way to put list optionally in this command format?

You need to put quotes around the environment variable value, since it contains characters the shell would otherwise interpret. Try:
docker run -itd --name example_container -e DDL_AUTO="{update,create,validate}" -p 80:8080 example_image

Related

docker run - autokill container already in use?

I was following this guide on customizing MySQL databases in Docker, and ran this command multiple times after making tweaks to the mounted sql files:
docker run -d -p 3306:3306 --name my-mysql -v /Users/pneedham/dev/docker-testing/sql-scripts:/docker-entrypoint-initdb.d/ -e MYSQL_ROOT_PASSWORD=supersecret -e MYSQL_DATABASE=company mysql
On all subsequent executions of that command, I would see an error like this:
docker: Error response from daemon: Conflict. The container name "/my-mysql" is already in use by container "9dc103de93b7ad0166bb359645c12d49e0aa4a3f2330b5980e455cec24843663". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
What I'd like to know is whether that docker run command can be modified to auto-kill the previous container (if it exists)? Or if there is a different command that has the same desired result.
If I were to create a shell script to do that for me, I'd first run docker ps -aqf "name=mysql" and if there is any output, use that resulting container ID by running docker rm -f $containerID. And then run the original command.
docker run command has a --rm arguments that deletes the container after the run is completed. see the docs . So, just change your command to
docker run --rm -d -p 3306:3306 --name my-mysql -v /Users/pneedham/dev/docker-testing/sql-scripts:/docker-entrypoint-initdb.d/ -e MYSQL_ROOT_PASSWORD=supersecret -e MYSQL_DATABASE=company mysql

Docker run not working it says requires at least 1 argument

I'm learning docker, and trying to run the existing images. The first command is working fine
command 1: docker run --name static-site -e AUTHOR="Mathi1" -d -P dockersamples/static-site
But the below command is throwing error
Command 2: docker run --name mvcdotnet -e AUTHOR="Mathi2" -d -p valkyrion/mvcdotnet
Error:
"docker run" requires at least 1 argument.
See 'docker run --help'.
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Run a command in a new container
According to docker help run:
…
-p, --publish list Publish a container's port(s) to the host
-P, --publish-all Publish all exposed ports to random ports
…
Command 1 uses -P (short form of --publish-all) and after that the image name. -P has no arguments.
Command 2 uses -p (short form of --publish list). -p expects an argument and I think docker mistakes the image name as the argument for -p (and expects an image name after that).

Docker image specific argument in ECS task definition

I have the below docker run command to launch a container:
docker run -d --name selenoid-ui \
--link selenoid \
-p 8080:8080 \
aerokube/selenoid-ui --selenoid-uri=http://selenoid:4444
Manage to run the command except the --selenoid-uri=http://selenoid:4444 part.
Tried to put the same in docker command, entry point and key value pairs but doesnt seem to work.
Any idea where shall I use this docker image specific argument in task definition?
Put this: Advanced container configuration > Environment > Command
--selenoid-uri=http://selenoid:4444
Use the Command property in your ContainerDefinition. See: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ecs-taskdefinition-containerdefinitions.html#cfn-ecs-taskdefinition-containerdefinition-command

Connection string in build variable VSTS

I am trying to start my docker image from a linux shell using build variables that pass into environment variables for the connection strings. When I start the app in the container it reports a malformed connection string. App runs when I compile it with the connection string hard coded so I know it works. I'm sure i'm probably not escaping the ; correctly or something like that. I notice that it just dumps each thing after ; on a new line in the VSTS log.
These are the Variables I created in VSTS
ConnString1 "Server=172.17.0.4\;Port=5432\;Database=dbname\;User Id=userid\;Password=mypassword\;"
ConnString2 "Server=172.17.0.4\;Port=5432\;Database=dbname2\;User Id=userid\;Password=mypassword\;"
This is my SSH command
docker image pull mydockername/myimage
docker run -d -e ConnString1=$(ConnString1) -e ConnString2=$(ConnString2) -v /home/mylinuxuser/CONFIGS/LIVE:/bin/Debug/netcoreapp2.0/publish/Configs --restart always -p 5000:5000 --name containername mydockername/myimage
This is a snippet of the output
2017-11-01T15:21:40.7137030Z Current agent version: '2.120.1'
[CONNSTRING1] --> ["Server=172.17.0.4\;Port=5432\;Database=dbname\;User Id=userid\;Password=mypassword\;"]
[CONNSTRING2] --> ["Server=172.17.0.4\;Port=5432\;Database=dbname2\;User Id=userid\;Password=mypassword\;"]
2017-11-01T15:21:43.2862730Z docker run -d -e ConnString1="Server=172.17.0.4\;Port=5432\;Database=dbname\;User Id=userid\;Password=mypassword\;" -e ConnString2="Server=172.17.0.4\;Port=5432\;Database=dbname2\;User Id=userid\;Password=mypassword\;" -v /home/********/CONFIGS/LIVE:/bin/Debug/netcoreapp2.0/publish/Configs --restart always -p 5000:5000 --name containername teh********/myimage
2017-11-01T15:21:43.2883710Z Port=5432\
2017-11-01T15:21:43.2895830Z Database=dbname\
2017-11-01T15:21:43.2906910Z User Id=userid\
2017-11-01T15:21:43.2918030Z Password=mypassword\
2017-11-01T15:21:43.2931210Z " -e ConnString2="Server=172.17.0.4\
2017-11-01T15:21:43.2944180Z Port=5432\
2017-11-01T15:21:43.2956140Z Database=dbame2\
2017-11-01T15:21:43.2968130Z User Id=userid\
2017-11-01T15:21:43.2980310Z Password=mypassword\
2017-11-01T15:21:43.2994020Z " -v /home/********/CONFIGS/LIVE:/bin/Debug/netcoreapp2.0/publish/Configs --restart always -p 5000:5000 --name containername teh********/myimage
2017-11-01T15:21:43.4025020Z 33237871bd9f7e1b3cf6665386ae12111d91a5c9e36d0e3781fa0e77af92e42a
These are the enviornment variables that get put into the container
ConnString2=Server=172.17.0.4Port=5432Database=beertradeauthUser Id=useridPassword=mypassword
ConnString1=Server=172.17.0.4Port=5432Database=beertradeUser Id=useridPassword=mypassword
Got this from vsts github and it worked
"The task doesn't change your inline script. it runs it as is. The issue is in your script.
Instead of:
docker run -d -e EnvVar1=$connstring1 ...
Does this work?
Take \ and double quotes out of User value
change script to(note quotes): docker run -d -e EnvVar1="${connstring1}" ..."

How to get `docker run` full arguments?

For example, I run a docker by docker run -d --name sonarqube -p 19000:9000 -p 19002:9002 -e SONARQUBE_JDBC_USERNAME=sonar -e SONARQUBE_JDBC_PASSWORD=123 --link sonarqube-mysql:mysql.
Then I lost my shell command history, but I want to know all my arguments.
How can I get them? (I need the arguments to copy/move/restart container)
Of course docker inspect is the way to go, but if you just want to "reconstruct" the docker run command, you have
https://github.com/nexdrew/rekcod
it says
Reverse engineer a docker run command from an existing container (via docker inspect).
docker inspect CONTAINER_NAME gives you that information.
Check docker inspect reference to see all available options: https://docs.docker.com/engine/reference/commandline/inspect/

Resources