scp guest@10.11.12.13:/usr/java/jdk-8u65-linux-x64.tar.gz .

sudo su
mkdir /usr/java
mv jdk-8u65-linux-x64.tar.gz /usr/java/
cd /usr/java/
tar -xzvf jdk-8u65-linux-x64.tar.gz

ln -s jdk1.8.0_65 current
update-alternatives –install “/usr/bin/javac” “javac” “/usr/java/current/bin/javac” 1
update-alternatives –install “/usr/bin/java” “java” “/usr/java/current/bin/java” 1

update-alternatives –display java
update-alternatives –display javac
exit

java -version

Hola !

Bueno, ahora voy a crear una imagen nueva desde cero con Docker.

Primero instala docker y prueba que funcione adecuadamente:

sudo apt-get update
# Install Docker:
wget -qO- https://get.docker.com/ | sh
# Add your user to docker group:
sudo groupadd docker
sudo gpasswd -a ${USER} docker
sudo service docker restart
# Test it works ok:
docker info
docker help

Ahora, crea un directorio para este experimento y crea los dos siguientes archivos: 1) Dockerfile

FROM debian:jessie

# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
RUN groupadd -r mysql && useradd -r -g mysql mysql

RUN mkdir /docker-entrypoint-initdb.d

# FATAL ERROR: please install the following Perl modules before executing /usr/local/mysql/scripts/mysql_install_db:
# File::Basename
# File::Copy
# Sys::Hostname
# Data::Dumper
RUN apt-get update && apt-get install -y perl pwgen --no-install-recommends && rm -rf /var/lib/apt/lists/*

# gpg: key 5072E1F5: public key "MySQL Release Engineering <mysql-build@oss.oracle.com>" imported
RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys A4A9406876FCBD3C456770C88C718D3B5072E1F5

ENV MYSQL_MAJOR 5.7
ENV MYSQL_VERSION 5.7.10-1debian8

RUN echo "deb http://repo.mysql.com/apt/debian/ jessie mysql-${MYSQL_MAJOR}" > /etc/apt/sources.list.d/mysql.list

# the "/var/lib/mysql" stuff here is because the mysql-server postinst doesn't have an explicit way to disable the mysql_install_db codepath besides having a database already "configured" (ie, stuff in /var/lib/mysql/mysql)
# also, we set debconf keys to make APT a little quieter
RUN { \
                echo mysql-community-server mysql-community-server/data-dir select ''; \
                echo mysql-community-server mysql-community-server/root-pass password ''; \
                echo mysql-community-server mysql-community-server/re-root-pass password ''; \
                echo mysql-community-server mysql-community-server/remove-test-db select false; \
        } | debconf-set-selections \
        && apt-get update && apt-get install -y mysql-server="${MYSQL_VERSION}" && rm -rf /var/lib/apt/lists/* \
        && rm -rf /var/lib/mysql && mkdir -p /var/lib/mysql

# comment out a few problematic configuration values
# don't reverse lookup hostnames, they are usually another container
RUN sed -Ei 's/^(bind-address|log)/#&/' /etc/mysql/my.cnf \
        && echo 'skip-host-cache\nskip-name-resolve' | awk '{ print } $1 == "[mysqld]" && c == 0 { c = 1; system("cat") }' /etc/mysql/my.cnf > /tmp/my.cnf \
        && mv /tmp/my.cnf /etc/mysql/my.cnf

VOLUME /var/lib/mysql

COPY docker-entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

EXPOSE 3306
CMD ["mysqld"]

2) docker-entrypoint.sh

#!/bin/bash
set -eo pipefail

# if command starts with an option, prepend mysqld
if [ "${1:0:1}" = '-' ]; then
        set -- mysqld "$@"
fi

if [ "$1" = 'mysqld' ]; then
        # Get config
        DATADIR="$("$@" --verbose --help 2>/dev/null | awk '$1 == "datadir" { print $2; exit }')"

        if [ ! -d "$DATADIR/mysql" ]; then
                if [ -z "$MYSQL_ROOT_PASSWORD" -a -z "$MYSQL_ALLOW_EMPTY_PASSWORD" -a -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then
                        echo >&2 'error: database is uninitialized and password option is not specified '
                        echo >&2 '  You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD'
                        exit 1
                fi

                mkdir -p "$DATADIR"
                chown -R mysql:mysql "$DATADIR"

                echo 'Initializing database'
                "$@" --initialize-insecure
                echo 'Database initialized'

                "$@" --skip-networking &
                pid="$!"

                mysql=( mysql --protocol=socket -uroot )

                for i in {30..0}; do
                        if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then
                                break
                        fi
                        echo 'MySQL init process in progress...'
                        sleep 1
                done
                if [ "$i" = 0 ]; then
                        echo >&2 'MySQL init process failed.'
                        exit 1
                fi

                if [ -z "$MYSQL_INITDB_SKIP_TZINFO" ]; then
                        # sed is for https://bugs.mysql.com/bug.php?id=20545
                        mysql_tzinfo_to_sql /usr/share/zoneinfo | sed 's/Local time zone must be set--see zic manual page/FCTY/' | "${mysql[@]}" mysql
                fi

                if [ ! -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then
                        MYSQL_ROOT_PASSWORD="$(pwgen -1 32)"
                        echo "GENERATED ROOT PASSWORD: $MYSQL_ROOT_PASSWORD"
                fi
                "${mysql[@]}" <<-EOSQL
                        -- What's done in this file shouldn't be replicated
                        --  or products like mysql-fabric won't work
                        SET @@SESSION.SQL_LOG_BIN=0;

                        DELETE FROM mysql.user ;
                        CREATE USER 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ;
                        GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION ;
                        DROP DATABASE IF EXISTS test ;
                        FLUSH PRIVILEGES ;
                EOSQL

                if [ ! -z "$MYSQL_ROOT_PASSWORD" ]; then
                        mysql+=( -p"${MYSQL_ROOT_PASSWORD}" )
                fi

                if [ "$MYSQL_DATABASE" ]; then
                        echo "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` ;" | "${mysql[@]}"
                        mysql+=( "$MYSQL_DATABASE" )
                fi

                if [ "$MYSQL_USER" -a "$MYSQL_PASSWORD" ]; then
                        echo "CREATE USER '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD' ;" | "${mysql[@]}"

                        if [ "$MYSQL_DATABASE" ]; then
                                echo "GRANT ALL ON \`$MYSQL_DATABASE\`.* TO '$MYSQL_USER'@'%' ;" | "${mysql[@]}"
                        fi

                        echo 'FLUSH PRIVILEGES ;' | "${mysql[@]}"
                fi

                echo
                for f in /docker-entrypoint-initdb.d/*; do
                        case "$f" in
                                *.sh)     echo "$0: running $f"; . "$f" ;;
                                *.sql)    echo "$0: running $f"; "${mysql[@]}" < "$f"; echo ;;
                                *.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${mysql[@]}"; echo ;;
                                *)        echo "$0: ignoring $f" ;;
                        esac
                        echo
                done

                if [ ! -z "$MYSQL_ONETIME_PASSWORD" ]; then
                        "${mysql[@]}" <<-EOSQL
                                ALTER USER 'root'@'%' PASSWORD EXPIRE;
                        EOSQL
                fi
                if ! kill -s TERM "$pid" || ! wait "$pid"; then
                        echo >&2 'MySQL init process failed.'
                        exit 1
                fi

                echo
                echo 'MySQL init process done. Ready for start up.'
                echo
        fi

        chown -R mysql:mysql "$DATADIR"
fi

exec "$@"

ASEGURATE DE QUE ESTE ARCHIVO TENGA PERMISOS DE EJECUCION: chmod +x docker-entrypoint.sh

Ahora invoca la construccion de la imagen:

docker build -t my-image-name-mysql-based .

Ahora ejecuta la imagen:

docker run --name my-experiment -e MYSQL_ROOT_PASSWORD=root -d my-image-name-mysql-based

Se puede verificar que si NO tenemos mysql en nuestro equipo local y ademas ejecutamos el comando

telnet localhost 3306

Veremos que no es posible conectar con el.

Pero, si hacemos:

docker exec -it my-experiment bash

Ya en el nuevo prompt del shell Inclusive podremos hacer esto:

mysql -u root -p

Y con el password que dimos originalmente, podermos entrar al prompt de mysql.

Listo !!!!

echo “Instalando docker… ultima version…”
wget -qO- https://get.docker.com/ | sh

echo “Para no tener que usar ‘sudo’ todo el tiempo…”
sudo usermod -aG docker gustavo
newgrp docker

echo “Verificando que la instalacion ha quedado correcta con hello-world image…”
docker run hello-world

echo “Instalando y ejecutando una imagen de Ubuntu…”
docker run -it ubuntu bash

echo “Instalando y ejecutando una imagen de whale-say”
docker run docker/whalesay cowsay gustavito

echo “Listando las imagenes que tengo localmente…”
docker images

echo “Que es esta ejecutando en docker en este momento?”
docker ps -a

echo “Instalando docker-compose”
sudo pip install docker-compose

echo “Creando un directorio y una archivo para docker-compose”
mkdir dk-cmp && cd dk-cmp
nano docker-compose.yml

echo “ejecutamdo el ensable…”
docker-compose up -d

echo “estresando el ensamble…”
ab -n 10000 -c 10 http://localhost/

© 2017 Goose Workshop Suffusion theme by Sayontan Sinha