How do i use a dockerfile to build containers?



  • Man page for docker run: http://bit.ly/2h77MqO
    Man page for docker start: http://bit.ly/2Au0GoM
    Man page for docker create: http://bit.ly/2j5l6jT

    You can run commands separately or put them into a file called a Dockerfile. For example these commands:

    $ docker create alpine /bin/sh -c "echo This is the main container > /etc/motd"
    $ docker start <container_id>
    $ docker commit <container_id>
    

    or you can put the following in a Dockerfile, which is basically the equivalent of the commands.

    $ cat Dockerfile
    ---
    FROM alpine
    RUN echo "This is the main container" > /etc/motd
    ---
    

    The Dockerfile is a lot more clearer to understand and read. This is saying build a container using the alpine image, and run the echo command on it.



© Lightnetics 2024