How to get logs out of a crashing Docker Desktop container - docker

This should be a duplicate of this question: Docker look at the log of an exited container. But I cannot get anything in that question to work.
I'm running container with this command (copied from Azure WebApp startup script)
docker run -d -p 5785:80 --name web-bt_0_096c876f -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITE_SITE_NAME=web-bt -e WEBSITE_AUTH_ENABLED=False -e PORT=80 -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=web-bt.azurewebsites.net -e WEBSITE_INSTANCE_ID=5c991bc5716941ff1fb1eb90137ac2f13e1afffea161b14571d6ea1fb1356b3d -e HTTP_LOGGING_ENABLED=1 bt:latest -e environment='Production' -e ASPNETCORE_ENVIRONMENT='Production'
This crashes for some reason (If I replace 'Production' with 'Development' in the two last parameters it works). This is what I'm trying to debug.
Now according to that other thread I should be able to do: docker logs -t web-bt_0_096c876f but this just returns immediately without printing anything at all.
Why is this empty. This returns nothing even if I replace the startup script with -e environment='Development' -e ASPNETCORE_ENVIRONMENT='Development' which actually works. I can browse to the web-app. But still no logs at all.
So how do I view the container logs/console output?

Related

Redis error: being thrown by Docker container: The queue is full

I have a number of docker containers running on a vm, all of which are using the same Redis cache db, each has the same Redis config settings:
-e CACHE_ENABLED=true -e CACHE_KEY_IGNORED_PROPS=meta -e CACHE_TYPE=redis -e CACHE_REDIS_PORT=6379 -e CACHE_REDIS_HOST=xx.xx.xx.x -e CACHE_MAX_AGE=60000 -e RATE_LIMIT_ENABLED=false -e WS_ENABLED=true -e CACHE_REDIS_TIMEOUT=2000 --log-opt max-size=10m --log-opt max-file=3
and I'm getting the following error in the Docker logs on just a couple of them, one after a while (days), another almost immediately after restarting:
"msg":"[Redis] Method getResponse errored: <...> \nError: The queue is full"}
...and am having a bit of a hard time trying to trouble shoot. Anyone have any advice???
Thanks so much!

Elastic Entreprise Search 7.9.0 with docker

I am trying to run Elastic Enterprise search 7.9.0 using the docker image by following the stpeps here : https://www.elastic.co/guide/en/enterprise-search/current/docker.html
docker run -p 3002:3002 -e elasticsearch.host='http://elastic:changeme#host.docker.internal:9200' -e elasticsearch.username=elastic -e elasticsearch.password=changeme -e allow_es_settings_modification=true -e secret_management.encryption_keys='[xxxxxxx]' docker.elastic.co/enterprise-search/enterprise-
search:7.9.0
I get the following warning and the service doesn't start :
Found java executable in PATH
Java version detected: 1.8.0_252 (major version: 8)
Enterprise Search is starting...
[2020-09-01T12:10:12.887+00:00][1][2000][app-server][INFO]: Enterprise Search version=7.9.0, JRuby version=9.2.9.0, Ruby version=2.5.7, Rails version=4.2.11.3
[2020-09-01T12:10:13.251+00:00][1][2000][app-server][INFO]: Successfully connected to Elasticsearch
[2020-09-01T12:10:25.949+00:00][1][2000][app-server][INFO]: [db_lock] [installation] Status: [Starting] Ensuring migrations tracking index exists
[2020-09-01T12:10:26.083+00:00][1][2000][app-server][INFO]: [db_lock] [installation] Status: [Finished] Ensuring migrations tracking index exists
[2020-09-01T12:10:26.981+00:00][1][2000][app-server][ERROR]:
--------------------------------------------------------------------------------
We need to perform 11/32 migrations before the service can be started.
Migrations pending: 20200604175830, 20200610113647, 20200611093100, 20200612155336, 20200617164710, 20200617210501, 20200623134305, 20200624153999, 20200709120000, 20200717204953, 20200723200724
Proceeding with migrations while indices are allowing writes can have unintended consequences.
Please enable read-only mode before proceeding:
https://www.elastic.co/guide/en/enterprise-search/current/read-only-mode.html
I don't know how to resolve this, as I can't set the read-only mode as the service is not starting.
Any idea ?
I'm not sure if this is the best solution, but here is what worked for me. Based on https://www.elastic.co/guide/en/enterprise-search/current/read-only-mode.html
Start Docker container with --enable-read-only-mode where it will run and then stop saying read only mode is enabled
Run the Docker container without --enable-read-only-mode until it successfully starts up and runs. Once successfully running I stopped the docker container
Started Docker container with --disable-read-only-mode where it will run and then stop saying read only mode is disabled
Run the docker container as you had previously, no issues
Using your docker command for example:
docker run -p 3002:3002 -e
elasticsearch.host='http://elastic:changeme#host.docker.internal:9200'
-e elasticsearch.username=elastic -e elasticsearch.password=changeme -e allow_es_settings_modification=true -e secret_management.encryption_keys='[xxxxxxx]'
docker.elastic.co/enterprise-search/enterprise- search:7.9.1
--enable-read-only-mode
docker run -p 3002:3002 -e
elasticsearch.host='http://elastic:changeme#host.docker.internal:9200'
-e elasticsearch.username=elastic -e elasticsearch.password=changeme -e allow_es_settings_modification=true -e secret_management.encryption_keys='[xxxxxxx]'
docker.elastic.co/enterprise-search/enterprise- search:7.9.1
docker run -p 3002:3002 -e
elasticsearch.host='http://elastic:changeme#host.docker.internal:9200'
-e elasticsearch.username=elastic -e elasticsearch.password=changeme -e allow_es_settings_modification=true -e secret_management.encryption_keys='[xxxxxxx]'
docker.elastic.co/enterprise-search/enterprise- search:7.9.1
--disable-read-only-mode
docker run -p 3002:3002 -e
elasticsearch.host='http://elastic:changeme#host.docker.internal:9200'
-e elasticsearch.username=elastic -e elasticsearch.password=changeme -e allow_es_settings_modification=true -e secret_management.encryption_keys='[xxxxxxx]'
docker.elastic.co/enterprise-search/enterprise- search:7.9.1
Back to normal. Good luck!
As response to #Christophvh, using docker-compose, you can enable read-only-mode simply using command, for example:
enterprise-search:
image: docker.elastic.co/enterprise-search/enterprise-search:${ELK_VERSION}
command: --enable-read-only-mode
You have to follow the same steps as described by #Brandon using the command method.

Environment variables are not getting created inside docker container

I am using Docker for Windows (2.2.0.5) on my Windows 10 Pro system.
I have created and build the docker image for my dotnet core app (SDK 3.1).
This app is connecting with external MySQL server to fetch data.
The app inside docker container is able to connect with database with hardcoded connection string. But not able to connect with arguments passed using -e flag. Upon investigation i figured out the environment variables are not getting created inside docker container.
Below is my docker run command -
docker run -d -p 5003:80 --name price-cat pricingcatalog:latest -e DB_HOST=165.202.xx.xx -e DB_DATABASE=pricing_catalog -e DB_USER=my-username -e DB_PASS=my-password
I am printing all environment variables created with container using C# code -
Console.WriteLine("All environment variables....Process");
foreach(DictionaryEntry envVar in Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Process)){
Console.WriteLine("key={0}, value={1}", envVar.Key, envVar.Value);
}
Console.WriteLine("============================");
Console.WriteLine("All environment variables....User");
foreach(DictionaryEntry envVar in Environment.GetEnvironmentVariables(EnvironmentVariableTarget.User)){
Console.WriteLine("key={0}, value={1}", envVar.Key, envVar.Value);
}
Console.WriteLine("============================");
Console.WriteLine("All environment variables....Machine");
foreach(DictionaryEntry envVar in Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Machine)){
Console.WriteLine("key={0}, value={1}", envVar.Key, envVar.Value);
}
Console.WriteLine("============================");
Below is what i am getting -
Is there anything i am missing out here.
Remember that all docker cli arguments must come before the image name. Anything after the image name is passed into the image as the command. If you're expecting those -e ... argument to set environment variables, they need to come before the image name:
docker run -d -p 5003:80 --name price-cat \
-e DB_HOST=165.202.xx.xx \
-e DB_DATABASE=pricing_catalog \
-e DB_USER=my-username \
-e DB_PASS=my-password \
pricingcatalog:latest

java running inside docker container cannot see environment variables

I am new with Docker. I have a small Java application that I am trying to run inside Docker. I have created a Dockerfile to build the image.
My application is reading Environment Variables to know which database to connect to.
When running the command
docker run -d -p 80:80 occm -e "MYSQL_USER=user" -e "MYSQL_PASSWORD=password" -e "MYSQL_PORT=3306" -e "MYSQL_HOST=somehost"
and then enumerating all the variables using System.getenv, I dont see any of them. So I have added to the Docker file
ENV MYSQL_HOST=localhost
now when I run the container I see this variable, but I see it with the localhost value and not somehost.
What am I doing wrong?
The problem is how you are running your docker image.
$ docker run --help
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
So, you are passing -e "..." -e "..." as command and arguments
You need to use -e as [OPTIONS].
$ docker run -d -p 80:80 -e "MYSQL_USER=user" -e "MYSQL_PASSWORD=password" -e "MYSQL_PORT=3306" -e "MYSQL_HOST=somehost" occm

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}" ..."

Resources