Docker,Error: cannot run migrations: database needs bootstrapping; - postgresql

This is what I have tried
docker run --rm \
> --link kong-database:kong-database \
> -e "KONG_DATABASE=postgres" \
> -e "KONG_PG_HOST=kong-database" \
> kong:latest kong migrations up
But I have
Error: cannot run migrations: database needs bootstrapping; run 'kong migrations bootstrap'
I do not understand what this actually means. If I try
docker run --rm --link kong-database:kong-database -e "KONG_DATABASE=postgres" -e "KONG_PG_HOST=kong-database" kong:latest kong migrations bootstrap
bootstrapping database...
Error: [PostgreSQL error] failed to bootstrap database: ERROR: syntax error at or near "NOT" (150)
I inspected kong-database
{
"Id": "d94ac442da9a399c1b865de49904e01085abe1ed8f0871af5830810c4c2a78dd",
"Created": "2019-04-19T07:18:59.534751317Z",
"Path": "docker-entrypoint.sh",
"Args": [
"postgres"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 18342,
"ExitCode": 0,
"Error": "",
"StartedAt": "2019-04-19T07:19:00.129193458Z",
"FinishedAt": "0001-01-01T00:00:00Z"
How it comes that I need to bootstrap database and why do I have problem?

You have to bootstrap the database before running kong. The up command is deprecated and replaced with bootstrap
Change
kong:latest kong migrations up
To
kong:latest kong migrations bootstrap

Related

Ansible fails with runuser: command not found

I am trying to provision a PostgreSQL server using role galaxyproject.postgresql. Using Vagrant box generic/centos7 this role fails with message
TASK [galaxyproject.postgresql : Initialize database (RedHat >= 7)] ************
fatal: [postgresql]: FAILED! => {"changed": true, "cmd": ["/usr/pgsql-9.6/bin/postgresql96-setup", "initdb"], "delta": "0:00:00.181409", "end": "2019-10-16 01:45:59.495713", "msg": "non-zero return code", "rc": 1, "start": "2019-10-16 01:45:59.314304", "stderr": "", "stderr_lines": [], "stdout": "Initializing database ... failed, see /var/lib/pgsql/9.6/initdb.log", "stdout_lines": ["Initializing database ... failed, see /var/lib/pgsql/9.6/initdb.log"]}
The file /var/lib/pgsql/9.6/initdb.log has the following message
/usr/pgsql-9.6/bin/postgresql96-setup: line 143: runuser: command not found
On the target node runuser is available
[root#postgresql ~]# which runuser
/sbin/runuser
So the problem seems to be that /sbin is not on the PATH when Ansible runs on target nodes.
How can I make runuser command available to Ansible? I don't want to change the external role galaxyproject.postgresql of course.
When I output PATH using Ansible debug it shows that PATH does not include sbin.
TASK [galaxyproject.postgresql : debug] ****************************************
ok: [postgresql] => {
"PATH": {
"changed": true,
"cmd": "echo $PATH",
"delta": "0:00:00.010478",
"end": "2019-10-16 02:12:14.882341",
"failed": false,
"rc": 0,
"start": "2019-10-16 02:12:14.871863",
"stderr": "",
"stderr_lines": [],
"stdout": "/usr/local/bin:/usr/bin",
"stdout_lines": [
"/usr/local/bin:/usr/bin"
]
}
}
If you need to add something into PATH, you can try to set environment for this module. I hadn't tried this for postgres module, but it should work:
- postgres_user: # or other module name you are using
user: foo # and other normal arguments
environment:
PATH: '$PATH:/sbin'
See also: https://docs.ansible.com/ansible/latest/user_guide/playbooks_environment.html

Failed to start container with specified command in json

I tried multiple ways to specify docker run command but ends up with errors.
When I run kubectl get pods which returns below error in status.
rpc error: code = 2 desc = failed to start container "3329716cb47a0f795b2372dd630ca1017b0bad8bf4ab0e05490d1ac5eb28ca1b": Error response from daemon: {"message":"container 3329716cb47a0f795b2372dd630ca1017b0bad8bf4ab0e05490d1ac5eb28ca1b encountered an error during CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2) extra info: {\"ApplicationName\":\"\",\"CommandLine\":\"\\\"powershell.exe -command\\\" \\\"docker run -e VSTS_ACCOUNT=apidrop -e VSTS_TOKEN=5zcp7yf5h2dofz642eykiwpo6lj6kniu4jkmgxljipocab4vc2wa -e VSTS_POOL=apexpool --name winvs2017_vstsagent raychen320/buildagent:1.0\\\"\",\"User\":\"\",\"WorkingDirectory\":\"C:\\\\BuildAgent\",\"Environment\":{\"DOTNET_DOWNLOAD_URL\":\"https://dotnetcli.blob.core.windows.net/dotnet/preview/Binaries/1.0.4/dotnet-win-x64.1.0.4.zip\",\"DOTNET_SDK_DOWNLOAD_URL\":\"https://dotnetcli.blob.core.windows.net/dotnet/Sdk/1.0.1/dotnet-dev-win-x64.1.0.1.zip\",\"DOTNET_SDK_VERSION\":\"1.0.1\",\"DOTNET_VERSION\":\"1.0.4\",\"KUBERNETES_PORT\":\"tcp://10.0.0.1:443\",\"KUBERNETES_PORT_443_TCP\":\"tcp://10.0.0.1:443\",\"KUBERNETES_PORT_443_TCP_ADDR\":\"10.0.0.1\",\"KUBERNETES_PORT_443_TCP_PORT\":\"443\",\"KUBERNETES_PORT_443_TCP_PROTO\":\"tcp\",\"KUBERNETES_SERVICE_HOST\":\"10.0.0.1\",\"KUBERNETES_SERVICE_PORT\":\"443\",\"KUBERNETES_SERVICE_PORT_HTTPS\":\"443\",\"NUGET_XMLDOC_MODE\":\"skip\",\"chocolateyUseWindowsCompression\":\"false\"},\"EmulateConsole\":false,\"CreateStdInPipe\":true,\"CreateStdOutPipe\":true,\"CreateStdErrPipe\":true,\"ConsoleSize\":[0,0]}"} 0 26s
The Json file I use for kubectl apply command to create pod is:
{
"apiVersion": "v1",
"kind": "Pod",
"metadata": {
"name": "buildagent",
"labels": {
"name": "buildagent"
}
},
"spec": {
"containers": [
{
"name": "buildagent",
"image": "raychen320/buildagent:1.0",
"command": [
"powershell.exe -command",
"docker run -e VSTS_ACCOUNT=apitest -e VSTS_TOKEN=tgctxxx -e VSTS_POOL=testpool --name myagent raychen320/buildagent:1.0"
],
"ports": [
{
"containerPort": 80
}
]
}
],
"nodeSelector": {
"beta.kubernetes.io/os": "windows"
}
}
}
What should I set in command?
You are trying to launch an executable named powershell.exe -command which obviously does not exist. What you should try to launch is more like :
command: "powershell.exe"
args:
- "-command"
- "docker run..."
Docker can't find powershell.exe in you system PATH.
Maybe you should use full path of powershell.exe in "command"

Error running postgresql96-setup initdb with Ansible

I am trying to automate the installation of a PostgreSQL database using Ansible.
However, the following task:
- name: Initialize Postgres
command: /usr/pgsql-9.6/bin/postgresql96-setup initdb
become: true
Results in this error:
fatal: [nexus-staging.chop.edu]: FAILED! => {
"changed": true,
"cmd": "/usr/pgsql-9.6/bin/postgresql96-setup initdb",
"delta": "0:00:00.043311",
"end": "2017-02-16 23:39:12.512727",
"failed": true,
"invocation": {
"module_args": {
"_raw_params": "/usr/pgsql-9.6/bin/postgresql96-setup initdb",
"_uses_shell": true,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"warn": true
},
"module_name": "command"
},
"rc": 1,
"start": "2017-02-16 23:39:12.469416",
"stderr": "",
"stdout": "Initializing database ... failed, see /var/lib/pgsql/9.6/initdb.log",
"stdout_lines": [
"Initializing database ... failed, see /var/lib/pgsql/9.6/initdb.log"
],
"warnings": []
}
The error in /var/lib/pgsql/9.6/initdb.log is:
/usr/pgsql-9.6/bin/postgresql96-setup: line 140: runuser: command not found
What is interesting is that if I run sudo /usr/pgsql-9.6/bin/postgresql96-setup initdb on the host, it runs successfully...
Any help would be appreciated.
Try with PATH environment variable defined explicitly in the task:
- name: Initialize Postgres
command: /usr/pgsql-9.6/bin/postgresql96-setup initdb
environment:
PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
become: true
Most likely the value of the path is set differently for interactive and non-interactive shell sessions.
Or locate the runuser executable and add the path before running the script:
command: PATH=/runuser/location:${PATH} /usr/pgsql-9.6/bin/postgresql96-setup initdb

Create kubernetes pod with volume using kubectl run

I understand that you can create a pod with Deployment/Job using kubectl run. But is it possible to create one with a volume attached to it? I tried running this command:
kubectl run -i --rm --tty ubuntu --overrides='{ "apiVersion":"batch/v1", "spec": {"containers": {"image": "ubuntu:14.04", "volumeMounts": {"mountPath": "/home/store", "name":"store"}}, "volumes":{"name":"store", "emptyDir":{}}}}' --image=ubuntu:14.04 --restart=Never -- bash
But the volume does not appear in the interactive bash.
Is there a better way to create a pod with volume that you can attach to?
Your JSON override is specified incorrectly. Unfortunately kubectl run just ignores fields it doesn't understand.
kubectl run -i --rm --tty ubuntu --overrides='
{
"apiVersion": "batch/v1",
"spec": {
"template": {
"spec": {
"containers": [
{
"name": "ubuntu",
"image": "ubuntu:14.04",
"args": [
"bash"
],
"stdin": true,
"stdinOnce": true,
"tty": true,
"volumeMounts": [{
"mountPath": "/home/store",
"name": "store"
}]
}
],
"volumes": [{
"name":"store",
"emptyDir":{}
}]
}
}
}
}
' --image=ubuntu:14.04 --restart=Never -- bash
To debug this issue I ran the command you specified, and then in another terminal ran:
kubectl get job ubuntu -o json
From there you can see that the actual job structure differs from your json override (you were missing the nested template/spec, and volumes, volumeMounts, and containers need to be arrays).

Jboss 5.1 in Dockerfile - how to reach the server in a browser

I have a dockerfile which looks like this:
FROM ubuntu:trusty
RUN DEBIAN_FRONTEND=noninteractive apt-get -yq upgrade
# Update to latest
RUN echo "deb http://archive.ubuntu.com/ubuntu trusty main universe" > /etc/apt/sources.list
RUN echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" > /etc/apt/sources.list.d/webupd8team-java.list
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C2518248EEA14886
RUN apt-get update
RUN apt-get upgrade -y
# Install basics
# RUN apt-get install -y python-software-properties software-properties-common unzip
RUN apt-get install -y unzip
# Install Java, auto-accepting the license
# RUN add-apt-repository -y ppa:webupd8team/java
# RUN apt-get update
# RUN echo oracle-java6-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections
# RUN apt-get install -y oracle-java6-installer
RUN echo oracle-java6-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections
# Install different Java versions
RUN DEBIAN_FRONTEND=noninteractive apt-get install -yq oracle-java6-installer
# Set environment variables pointing to different Java installations
ENV JAVA_HOME /usr/lib/jvm/java-6-oracle
ENV JAVA6_HOME /usr/lib/jvm/java-6-oracle
# Ensure Java 6 is the default version
RUN update-java-alternatives -s java-6-oracle
# Install JBoss 5.1.0.GA
RUN wget -O jboss.zip http://sourceforge.net/projects/jboss/files/JBoss/JBoss-5.1.0.GA/jboss-5.1.0.GA-jdk6.zip/download
RUN unzip jboss.zip && mv jboss-5.1.0.GA /opt
RUN cd /opt/jboss-5.1.0.GA/bin && chmod +x *.sh
CMD /opt/jboss-5.1.0.GA/bin/run.sh
# Clean-up to reduce the image size
RUN apt-get clean
EXPOSE 8080
i build it than with:
sudo docker build -t dockerfile .
everything builds fine. so I start the server with:
sudo docker run -it --publish 127.0.0.1:8080:8080 dockerfile:latest
I can see that the server starts correctly
If I enter the URL 127.0.0.1:8080 i got an error site:
the connection was reset - the connection to the server was reset
while the page was loading
How do I get a connection to the server in my browser?
The inspect of my container looks like this:
[{
"Args": [
"-c",
"/opt/jboss-5.1.0.GA/bin/run.sh"
],
"Config": {
"AttachStderr": false,
"AttachStdin": false,
"AttachStdout": false,
"Cmd": [
"/bin/sh",
"-c",
"/opt/jboss-5.1.0.GA/bin/run.sh"
],
"CpuShares": 0,
"Cpuset": "",
"Domainname": "",
"Entrypoint": null,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"JAVA_HOME=/usr/lib/jvm/java-6-oracle",
"JAVA6_HOME=/usr/lib/jvm/java-6-oracle"
],
"ExposedPorts": {
"8080/tcp": {}
},
"Hostname": "054aaccfd754",
"Image": "dockerfile:latest",
"Memory": 0,
"MemorySwap": 0,
"NetworkDisabled": false,
"OnBuild": null,
"OpenStdin": false,
"PortSpecs": null,
"SecurityOpt": null,
"StdinOnce": false,
"Tty": false,
"User": "",
"Volumes": null,
"WorkingDir": ""
},
"Created": "2014-11-27T11:35:34.538502513Z",
"Driver": "aufs",
"ExecDriver": "native-0.2",
"HostConfig": {
"Binds": null,
"CapAdd": null,
"CapDrop": null,
"ContainerIDFile": "",
"Devices": [],
"Dns": null,
"DnsSearch": null,
"ExtraHosts": null,
"Links": null,
"LxcConf": [],
"NetworkMode": "bridge",
"PortBindings": {
"8080/tcp": [
{
"HostIp": "172.17.42.1",
"HostPort": "8080"
}
]
},
"Privileged": false,
"PublishAllPorts": false,
"RestartPolicy": {
"MaximumRetryCount": 0,
"Name": ""
},
"VolumesFrom": null
},
"HostnamePath": "/var/lib/docker/containers/054aaccfd7544a0c14a9f53f94ea2be0c2d6d58437c5311f6507ce2e4466bfa7/hostname",
"HostsPath": "/var/lib/docker/containers/054aaccfd7544a0c14a9f53f94ea2be0c2d6d58437c5311f6507ce2e4466bfa7/hosts",
"Id": "054aaccfd7544a0c14a9f53f94ea2be0c2d6d58437c5311f6507ce2e4466bfa7",
"Image": "f820f5fe9d26c8e896b9d902492ba66f8ed679792047c9c3147b7045df0ed98f",
"MountLabel": "",
"Name": "/sleepy_franklin",
"NetworkSettings": {
"Bridge": "docker0",
"Gateway": "172.17.42.1",
"IPAddress": "172.17.0.5",
"IPPrefixLen": 16,
"MacAddress": "02:42:ac:11:00:05",
"PortMapping": null,
"Ports": {
"8080/tcp": [
{
"HostIp": "172.17.42.1",
"HostPort": "8080"
}
]
}
},
"Path": "/bin/sh",
"ProcessLabel": "",
"ResolvConfPath": "/var/lib/docker/containers/054aaccfd7544a0c14a9f53f94ea2be0c2d6d58437c5311f6507ce2e4466bfa7/resolv.conf",
"State": {
"ExitCode": 0,
"FinishedAt": "0001-01-01T00:00:00Z",
"Paused": false,
"Pid": 4236,
"Restarting": false,
"Running": true,
"StartedAt": "2014-11-27T11:35:35.120814905Z"
},
"Volumes": {},
"VolumesRW": {}
}
EDIT after jottrs answers:
the logs says:
....
11:36:32,963 INFO [TomcatDeployment] deploy, ctxPath=/admin-console
11:36:33,067 INFO [config] Initializing Mojarra (1.2_12-b01-FCS) for context '/admin-console'
11:36:38,001 INFO [TomcatDeployment] deploy, ctxPath=/
11:36:38,068 INFO [TomcatDeployment] deploy, ctxPath=/jmx-console
11:36:38,232 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on http-127.0.0.1-8080
11:36:38,314 INFO [AjpProtocol] Starting Coyote AJP/1.3 on ajp-127.0.0.1-8009
11:36:38,341 INFO [ServerImpl] JBoss (Microcontainer) [5.1.0.GA (build: SVNTag=JBoss_5_1_0_GA date=200905221634)] Started in 1m:1s:805ms
nothing more....
because of Jottrs IP mention:
As far as i understood, I bind my server to 127.0.0.1:8080 with the start command:
sudo docker run -it --publish 127.0.0.1:8080:8080 dockerfile:latest
If I look with ifconfig i have the docker file running on:
$ ifconfig
docker0 Link encap:Ethernet Hardware Adresse 56:84:7a:fe:97:99
inet Adresse:172.17.42.1 Bcast:0.0.0.0 Maske:255.255.0.0
inet6-Adresse: fe80::5484:7aff:fefe:9799/64 Gültigkeitsbereich:Verbindung
UP BROADCAST RUNNING MULTICAST MTU:1500 Metrik:1
RX-Pakete:86 Fehler:0 Verloren:0 Überläufe:0 Fenster:0
TX-Pakete:101 Fehler:0 Verloren:0 Überläufe:0 Träger:0
Kollisionen:0 Sendewarteschlangenlänge:0
RX-Bytes:4983 (4.9 KB) TX-Bytes:12056 (12.0 KB)
But with $ sudo docker inspect --format "{{ .NetworkSettings.IPAddress }}" 054
i get 172.17.0.5
But I also get no connection in my browser with the URL 172.17.0.5:8080 or URL 172.17.42.1:8080
also if I start with $ sudo docker run -d --publish 172.17.42.1:8080:8080 dockerfile:latest (the ifconfig IP) I will not get a connection (and still no reaction on the logs)
$ sudo docker exec -it 228 bash
root#22870ce4265e:/# cat /etc/hosts
172.17.0.6 22870ce4265e
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
The problem is JBoss not Docker. JBoss listen per default only to localhost:8080 Jboss only works on localhost:8080 ,but doesnt reply when called by ip (I'm not a JBoss guy so you have to try "-b 0.0.0.0" or to provide a server.xml via ADD in your Dockerfile).
When you run (in my case I called the container jboss)
sudo docker exec jboss apt-get install curl -y
sudo docker exec jboss curl localhost:8080
you notice that JBoss runs and is accessable.