Dockerfile과 Bash

  • View
    621

  • Download
    3

Embed Size (px)

Text of Dockerfile과 Bash

  • Dockerfile Bash

    Docker Seoul Meetup #2 / September 27, 2014

    http://pyrasis.com

  • Dockerfile RUN, CMD, ENTRYPOINT Shell

    RUN: CMD, ENTRYPOINT: ,

  • RUN cd /etcRUN echo "127.0.0.1 hello" >> hosts#

    RUN

    RUN cd /etc && echo "127.0.0.1 hello" >> hosts

    WORKDIR /etcRUN echo "127.0.0.1 hello" >> hosts

  • FROM ubuntu:14.04

    ENV DEBIAN_FRONTEND noninteractive

    RUN apt-get updateRUN echo "mysql-server mysql-server/root_password password" | debconf-set-selectionsRUN echo "mysql-server mysql-server/root_password_again password" | debconf-set-selectionsRUN apt-get install -y mysql-server

    RUN , () ENV ENV RUN Bash ,

  • Bash(Bourne Again Shell) Shell

    CentOS: sh -> bashUbuntu: sh -> dash(Debian Almquist Shell)

  • $ echo "hello" > ./hello.txt$ echo "hello" > /dev/null

    (stdout)

    $ echo "cat" < ./hello.txt (stdin)

    $ echo "world" >> ./hello.txt

    2>2>>

    (stderr) ,

  • &> (stdout) (stderr)

    1>&2 (stdout) (stderr)

    2>&1$ cat world.txt > /dev/null 2>&1

    (stderr) (stdout)

    $ ls -al | grep .txt

  • $ export HELLO=world

    $ HELLO=world

  • $ sudo docker rm $(docker ps -aq)$ echo $(date)$ sudo docker rm `docker ps -aq`$ echo `date`

    (stdout)

    $ echo '$USER'$USER

    $ echo "$USER"pyrasis

  • $ str="World"$ echo "Hello ${str}"Hello World$ echo "Hello $str"Hello World

    $ WORLD=$ WORLD=${WORLD:-"abcd"}$ echo $WORLDabcd

    , NULL

  • $ sudo docker run -d --name hello busybox:latest$ sudo docker run \ -d \ --name hello \ busybox:latest

  • $ cat
  • $ printf 80\\nexampleuser\\ny | example-configPort: 80User: exampleuserSave Configuration (y/n): y

    .

    $ sed -i "s/hello/world/g" hello.txt

    #!/bin/bash

    REVISION=$(expr substr $(git rev-parse --verify HEAD) 1 7)

    Git .

  • Dockerfile

  • FROM ubuntu:14.04

    RUN apt-get updateRUN apt-get install -y nginxRUN echo "\ndaemon off;" >> /etc/nginx/nginx.confRUN chown -R www-data:www-data /var/lib/nginx

    WORKDIR /etc/nginx

    CMD ["nginx"]

    EXPOSE 80EXPOSE 443

  • #!/bin/bash

    mysql_install_db --user mysql > /dev/null

    cat > /tmp/sql

  • rbenv Ruby FROM ubuntu:14.04

    RUN apt-get updateRUN apt-get install -y autoconf bison build-essential libssl-dev \ libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev gitRUN apt-get install -y nginx nodejs curl libpq-dev

    RUN git clone https://github.com/sstephenson/rbenv.git /root/.rbenvRUN git clone https://github.com/sstephenson/ruby-build.git /root/.rbenv/plugins/ruby-buildENV PATH /root/.rbenv/bin:/root/.rbenv/shims:$PATH

    ENV CONFIGURE_OPTS --disable-install-docRUN rbenv install 2.1.3RUN rbenv global 2.1.3RUN rbenv init -

    RUN echo 'gem: --no-rdoc --no-ri' >> /root/.gemrcRUN gem install bundlerRUN rbenv rehash

    RUN echo "daemon off;" >> /etc/nginx/nginx.confRUN rm -rf /etc/nginx/sites-enabled/defaultADD exampleapp.conf /etc/nginx/sites-enabled/exampleapp.conf

    WORKDIR /tmpADD Gemfile GemfileADD Gemfile.lock Gemfile.lockRUN bundle install

    ADD ./ /var/www/exampleappWORKDIR /var/www/exampleappRUN chmod +x entrypoint.sh

    EXPOSE 80ENTRYPOINT ./entrypoint.sh

  • #!/bin/bash

    echo "export ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe" > /etc/profile.d/oracle.shecho "export ORACLE_SID=XE" >> /etc/profile.d/oracle.shecho "export PATH=$PATH:/u01/app/oracle/product/11.2.0/xe/bin" >> /etc/profile.d/oracle.shsource /etc/profile.d/oracle.sh

    printf 8080\\n1521\\n$ORACLE_PASSWORD\\n$ORACLE_PASSWORD\\nn | /etc/init.d/oracle-xe configureecho "root:$ORACLE_PASSWORD" | chpasswd

    /usr/sbin/sshd -D

    printf

  • FROM ubuntu:14.04

    RUN cd /etc/apt && \ sed -i 's/archive.ubuntu.com/ftp.daum.net/g' sources.list && \ sed -i 's/archive.ubuntu.com/ftp.daum.net/g' sources.list.d/proposed.list

    RUN apt-get updateRUN apt-get install -y nginx

    sed

  • [Unit]Description=Announce WebBindsTo=web.service

    [Service]EnvironmentFile=/etc/environmentExecStart=/bin/sh -c \ "while true; \ do \ etcdctl set /services/web/nginx \ '{ \"host\": \"${COREOS_PUBLIC_IPV4}\", \"port\": 80 }' \ --ttl 60; \

    sleep 45; \ done"ExecStop=/usr/bin/etcdctl rm /services/web/nginx

    [X-Fleet]MachineOf=web.service

  • " Docker" http://www.pyrasis.com/private/2014/11/30/publish-docker-for-the-really-impatient-book

  • " " http://www.pyrasis.com/private/2014/09/30/publish-the-art-of-amazon-web-services-book

    dockerfile-and-bash_1234567891011121314151617181920

    aws