docker tag an image

A docker build i.e.

docker build <Directory>

Should create an image... this image if all goes well should have the name of the directory. Sometimes things have warnings or errors.

You have however manually name an image

docker tag 0e5574283393 fedora/httpd:version1.0

Docker Build

TO do a docker build and create a named image try this

docker build -t tim/postgres:1.0 ubuntu1604_postgres/

Example Docker file

# docker build -t ubuntu1604_osm
FROM ubuntu:16.04

# Ensure `add-apt-repository` is present
RUN apt-get update -y

# Add PostgreSQL client
RUN apt-get install -y postgresql-client postgresql postgresql-contrib

RUN mkdir /mnt/data && chown postgres /mnt/data
#Need to add the osm2pgsql utility
RUN apt-get install -y osm2pgsql

USER postgres
RUN echo "CREATE USER gis WITH SUPERUSER PASSWORD 'gispass';" > /tmp/ &&\
    echo "create database gis_db with owner=gis;" >> /tmp/ &&\
    service postgresql start &&\
    sleep 5s &&\
    cat /tmp/ &&\
    sleep 2s &&\
    cat /tmp/ | psql &&\
    echo "create extension \"postgis\";" | psql -d gis_db 

# And add ``listen_addresses`` to ``/etc/postgresql/9.5/main/postgresql.conf``
RUN echo "host all  all  md5" >> /etc/postgresql/9.5/main/pg_hba.conf &&\
    echo "listen_addresses='*'" >> /etc/postgresql/9.5/main/postgresql.conf

# Expose the PostgreSQL port

# Add VOLUMEs to allow backup of config, logs and databases
VOLUME  ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]

# Set the default command to run when starting the container
#CMD ["/usr/lib/postgresql/9.5/bin/postgres", "-D", "/var/lib/postgresql/9.5/main", "-c", "config_file=/etc/postgresql/9.5/main/postgresql.conf"]

ADD gcc-states-latest.osm.pbf /mnt/data/
#Need to add the osm2pgsql utility
RUN service postgresql start &&\
    cd /mnt/data &&\
    sleep 5s &&\
    osm2pgsql -C 8000 --slim --number-processes 4 -c -d gis_db gcc-states-latest.osm.pbf
#CMD ["/usr/lib/postgresql/9.5/bin/postgres", "-D", "/var/lib/postgresql/9.5/main", "-c", "config_file=/etc/postgresql/9.5/main/postgresql.conf"]

Please note that whilst this will build and load the Postgres data for the gcc it will NOT autorun it as I have the CMD line commented out.

Running this image

TO see the image

dock image list


REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
tim/postgres        1.0                 93384e0f5b90        2 minutes ago       910MB

So I run (I want to port forward 5432 in and out)

dock run -p 5432:5432 tim:postgres