Cannot publish any docker containers - docker

I had docker 1.7.1, I was following james turbnall the docker book .
created two images (apache, jekyll) , created a jekyll container then
I created apache container as well with the -P tag with EXPOSE 80 in the docker file but as i ran docker port 80 but no public port error.
then i upgraded to docker 1.8.1 but nothing changed I tried -P , -p , EXPOSE and every argument but i can't get it fixed .
My ports column when running Docker ps -a is always empty.
Dockerfile:
FROM ubuntu:14.04
MAINTAINER AbdelRhman Khaled
ENV REFRESHED_AT 2015-09-05
RUN apt-get -yqq update
RUN apt-get -yqq install apache2
VOLUME [ "/var/www/html" ]
WORKDIR /var/www/html
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www.data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid
ENV APACHE_RUN_DIR /var/run/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
RUN mkdir -p $APACHE_RUN_DIR $APACHE_LOCK_DIR $APACHE_LOG_DIR
EXPOSE 80
ENTRYPOINT [ "/usr/sbin/apache2" ]
CMD [ "-D", "FOREGROUND" ]
commands:
$ sudo docker build -t jamtur01/apache .
$ sudo docker run -d -P --volumes-from james_blog jamtur01/apache
$ sudo docker port container_ID 80
Error: No public port '80/tcp' published for aa99fef6544a

Just changed the Image Tag name and All is working fine now.

Related

Flag provided but not defined

I have following Dockerfile:
FROM golang:1.9.2
ADD . /go/src/github.com/golang/example/outyet
ADD . /go/src/github.com/derekparker/delve/cmd/dlv
RUN go install github.com/golang/example/outyet
RUN go install github.com/derekparker/delve/cmd/dlv
RUN ["chmod", "+x", "/go/src/github.com/golang/example/outyet/bootstrap.sh"]
CMD ["/go/src/github.com/golang/example/outyet/bootstrap.sh"]
EXPOSE 8091
EXPOSE 5432
And following bootstrap.sh:
#!/bin/sh
go build -gcflags='-N -l' github.com/golang/example/outyet &&
dlv --listen=:5432 --headless=true --api-version=2 exec outyet;
After running container and image with following lines:
sudo docker build -t outyet .
sudo docker run -p 6060:8091 -p 5432:5432 --name test --rm outyet
I get following output:
flag provided but not defined: -listen
Usage of dlv:
-http string
Listen address (default ":8091")
-poll duration
Poll period (default 1s)
-version string
Go version (default "1.4")
When I run bootstrap.sh locally on my ubuntu hostmachine everything works fine. What is wrong?
I was able to fix it, my Dockerfile looks like this now:
FROM golang:1.9.2
ADD . /go/src/github.com/golang/example/outyet
RUN go install github.com/golang/example/outyet
RUN ["chmod", "+x", "/go/src/github.com/golang/example/outyet/bootstrap.sh"]
RUN ["chmod", "+x", "/go/bin/outyet"]
CMD ["/go/src/github.com/golang/example/outyet/bootstrap.sh"]
EXPOSE 8091
EXPOSE 5432
bootstrap.sh:
#!/bin/sh
go get github.com/derekparker/delve/cmd/dlv;
go build -gcflags='-N -l' github.com/golang/example/outyet &&
dlv --listen=:5432 --headless=true --api-version=2 exec outyet
And run it as following:
sudo docker build -t outyet .
sudo docker run --security-opt=seccomp:unconfined --net=host --name test --rm outyet

amc, aerospike are not recognized inside docker container

I've docker ubuntu 16.04 image and I'm running aerospike server in it.
$ docker run -d -p 3000:3000 -p 3001:3001 -p 3002:3002 -p 3003:3003 -p 8081:8081 --name aerospike aerospike/aerospike-server
The docker container is running successfully.
$ docker ps
CONTAINER ID IMAGE COMMAND
CREATED STATUS PORTS
NAMES
b0b4c63d7e22 aerospike/aerospike-server "/entrypoint.sh asd"
36 seconds ago Up 35 seconds 0.0.0.0:3000-3003->3000-3003/tcp, 0.0.0.0:8081->8081/tcp aerospike
I've logged into the docker container
$ docker exec -it b0b4c63d7e22 bash
root#b0b4c63d7e22:/#
I have listed the directories -
root#b0b4c63d7e22:/# ls
bin boot core dev entrypoint.sh etc home lib lib64 media mnt opt
proc root run sbin srv sys tmp usr var
root#b0b4c63d7e22:/#
I changed the directory to bin folder and listed the commands
root#b0b4c63d7e22:/# cd bin
root#b0b4c63d7e22:/bin# ls
bash dnsdomainname ip mount readlink systemctl
touch zegrep
cat domainname journalctl mountpoint rm systemd
true zfgrep
chgrp echo kill mv rmdir systemd-ask-
password umount zforce
chmod egrep ln netstat run-parts systemd-escape
uname zgrep
chown false login networkctl sed systemd-inhibit
uncompress zless
cp fgrep loginctl nisdomainname sh systemd-machine-
id-setup vdir zmore
dash findmnt ls pidof sh.distrib systemd-notify
wdctl znew
date grep lsblk ping sleep systemd-tmpfiles
which
dd gunzip mkdir ping6 ss systemd-tty-ask-
password-agent ypdomainname
df gzexe mknod ps stty tailf
zcat
dir gzip mktemp pwd su tar
zcmp
dmesg hostname more rbash sync tempfile
zdiff
Then I want to check the service -
root#b0b4c63d7e22:/bin# service amc status
amc: unrecognized service
Aerospike's official docker container does not have Aerospike Server running as a daemon, but instead as a foreground process. You can see this in the official github DOCKERFILE.
AMC is not part of Aerospike's Docker Image. It is up to you to run AMC from the environment of your choosing.
Finally, since you have not created a custom aerospike.conf file, Aerospike Server will only respond to clients on the Docker internal network. The -p parameters are not sufficient in itself to expose Aerospike's ports to clients, you'd also need to configure access-address, if you'd want client access from outside of the docker environment. Read more about Aerospike's networking at: https://www.aerospike.com/docs/operations/configure/network/general
You can build your own Docker container for amc to connect to aerospike running on containers.
Here is a sample Dockerfile for AMC.
cat Dockerfile
FROM ubuntu:xenial
ENV AMC_VERSION 4.0.13
# Install AMC server
RUN \
apt-get update -y \
&& apt-get install -y wget python python-argparse python-bcrypt python-openssl logrotate net-tools iproute2 iputils-ping \
&& wget "https://www.aerospike.com/artifacts/aerospike-amc-community/${AMC_VERSION}/aerospike-amc-community-${AMC_VERSION}_amd64.deb" -O aerospike-amc.deb \
&& dpkg -i aerospike-amc.deb \
&& apt-get purge -y
# Expose Aerospike ports
#
# 8081 – amc port
#
EXPOSE 8081
# Execute the run script in foreground mode
ENTRYPOINT ["/opt/amc/amc"]
CMD [" -config-file=/etc/amc/amc.conf -config-dir=/etc/amc"]
#/opt/amc/amc -config-file=/etc/amc/amc.conf -config-dir=/etc/amc
# Docker build sample:
# docker build -t amctest .
# Docker run sample for running amc on port 8081
# docker run -tid --name amc -p 8081:8081 amctest
# and access through http://127.0.0.1:8081
Then you can build the image:
docker build -t amctest .
Sending build context to Docker daemon 50.69kB
Step 1/6 : FROM ubuntu:xenial
---> 2fa927b5cdd3
Step 2/6 : ENV AMC_VERSION 4.0.13
---> Using cache
---> edd6bddfe7ad
Step 3/6 : RUN apt-get update -y && apt-get install -y wget python python-argparse python-bcrypt python-openssl logrotate net-tools iproute2 iputils-ping && wget "https://www.aerospike.com/artifacts/aerospike-amc-community/${AMC_VERSION}/aerospike-amc-community-${AMC_VERSION}_amd64.deb" -O aerospike-amc.deb && dpkg -i aerospike-amc.deb && apt-get purge -y
---> Using cache
---> f916199044d8
Step 4/6 : EXPOSE 8081
---> Using cache
---> 06f7888c1721
Step 5/6 : ENTRYPOINT /opt/amc/amc
---> Using cache
---> bc39346cd94f
Step 6/6 : CMD -config-file=/etc/amc/amc.conf -config-dir=/etc/amc
---> Using cache
---> 8ae4300e7c7c
Successfully built 8ae4300e7c7c
Successfully tagged amctest:latest
and finally run it with port forwarding to port 8081:
docker run -tid --name amc -p 8081:8081 amctest
a07cdd8bf8cec6ba41ce068c01544920136a6905e7a05e9a2c315605f62edfce

Environment variables with docker run -e

Here is my Dockerfile :
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get install -y default-jdk
ADD sample-docker-1.0-SNAPSHOT.jar app.jar
EXPOSE 8080
ENV SITENAME="ASDASD"
ENTRYPOINT ["java", "-jar", "app.jar"]
and here is a bit of Java code that i use:
#Value("${SITENAME:testsite}")
private String siteName;
with this setup everything works good and environment value of SITENAME is indeed "ASDASD". But when i try to set that variable with:
docker run -P -d --name spring spring-app -e SITENAME='DOCKERlocal'
it doesn't work (value is the one from Dockerfile). What am i missing here ?
You want to pass the -e to the docker command. So:
docker run -P -d --name spring -e "SITENAME=DOCKERlocal" spring-app
As you are doing it, you are passing it to the image entrypoint.

Why does docker "--filter ancestor=imageName" find the wrong container?

I have a deployment script that builds new images, stop the existing containers with the same image names, then starts new containers from those images.
I stop the container by image name using the answer here: Stopping docker containers by image name - Ubuntu
But this command stops containers that don't have the specified image name. What am I doing wrong?
See here to watch docker stopping the wrong container:
Here is the dockerfile:
FROM ubuntu:14.04
MAINTAINER j#eka.com
# Settings
ENV NODE_VERSION 5.11.0
ENV NVM_DIR /root/.nvm
ENV NODE_PATH $NVM_DIR/versions/node/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
# Replace shell with bash so we can source files
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
# Install libs
RUN apt-get update
RUN apt-get install curl -y
RUN curl https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash \
&& chmod +x $NVM_DIR/nvm.sh \
&& source $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default
RUN apt-get clean
# Install app
RUN mkdir /app
COPY ./app /app
#Run the app
CMD ["node", "/app/src/app.js"]
I build like so:
docker build -t "$serverImageName" .
and start like so:
docker run -d -p "3000:"3000" -e db_name="$db_name" -e db_username="$db_username" -e db_password="$db_password" -e db_host="$db_host" "$serverImageName"
Why not use the container name to differentiate you environments?
docker run -d --rm --name nginx-dev nginx
40ca9a6db09afd78e8e76e690898ed6ba2b656f777b84e7462f4af8cb4a0b17d
docker run -d --rm --name nginx-qa nginx
347b32c85547d845032cbfa67bbba64db8629798d862ed692972f999a5ff1b6b
docker run -d --rm --name nginx nginx
3bd84b6057b8d5480082939215fed304e65eeac474b2ca12acedeca525117c36
Then use docker ps
docker ps -f name=nginx$
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3bd84b6057b8 nginx "nginx -g 'daemon ..." 30 seconds ago Up 28 seconds 80/tcp, 443/tcp nginx
According to the docs --filter ancestor could be finding the wrong containers if they are in any way children of other containers.
So to be sure my images are separate right from the start I added this line to the start of my dockerfile, after the FROM and MAINTAINER commands:
RUN echo DEVTESTLIVE: This line ensures that this container will never be confused as an ancestor of another environment
Then in my build scripts after copying the dockerfile to the distribution folder I replace DEVTESTLIVE with the appropriate environment:
sed -i -e "s/DEVTESTLIVE/$env/g" ../dist/server/dockerfile
This seems to have worked; I now have containers for all three environments running simultaneously and can start and stop them automatically through their image names.

Why am I getting a docker container with no IPAddress?

I have a Dockerfile to build mongodb on Centos 6:
# Build docker image for mongodb
FROM test
MAINTAINER ...
# Set up mongodb yum repo entry
# https://www.liquidweb.com/kb/how-to-install-mongodb-on-centos-6/
RUN echo -e "\
[mongodb]\n\
name=MongoDB Repository\n\
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/\n\
gpgcheck=0\n\
enabled=1\n" >> /etc/yum.repos.d/mongodb.repo
# Install mongodb
RUN yum install -y mongodb-org
# Set up directory requirements
RUN mkdir -p /data/db /var/log/mongodb /var/run/mongodb
VOLUME ["/data/db", "/var/log/mongodb"]
# Expose port 27017 from the container to the host
EXPOSE 27017
# Start mongodb
ENTRYPOINT ["/usr/bin/mongod"]
CMD ["--port", "27017", "--dbpath", "/data/mongodb", "--pidfilepath", "/var/run/mongodb/mongod.pid"]
I build it:
% docker build -t mongodb .
...
Step 8 : CMD ["--port", "27017", "--dbpath", "/data/mongodb", "--pidfilepath", "/var/run/mongodb/mongod.pid"]
---> Running in 4025f6c86f81
---> 46d71068d2e0
Removing intermediate container 4025f6c86f81
Successfully built 46d71068d2e0
I run it:
% docker run -d -P 46d71068d2e0
0bdbfd6fe86ca31c678ba45ac1328958e8126b05c717877287e725924451f7f8
I inspect it:
% docker inspect 0bdbfd6fe86ca31c678ba45ac1328958e8126b05c717877287e725924451f7f8
[{
...
"NetworkSettings": {
"Bridge": "",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"PortMapping": null,
"Ports": null
},
I have no IPAddress.
My /etc/default/docker has only DNS options in it:
DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"
Why? I am finding it challenging to use this without an address.
If I replace the ENTRYPOINT and CMD with CMD [], I can run the container (docker run -t -i mongodb /bin/sh) and it has an address and I can start mongod from within the container. And it is externally accessible as a mongodb server that I can insert rows into and query.
So the answer is that mongodb was failing to start up because I had specified a non-existent path for the data:
"--dbpath", "/data/mongodb"
when I had created an entirely different directory earlier:
RUN mkdir -p /data/db /var/log/mongodb /var/run/mongodb
VOLUME ["/data/db", "/var/log/mongodb"]
When started with docker run -P -d, there was no output. I tried to docker run -t -i this container to see results in a terminal, but I was getting this error:
CMD = /bin/sh when using ENTRYPOINT but empty CMD
"When using entrypoint without a CMD the CMD is set to /bin/sh instead of the expected nothing."

Resources