happysundar
6/7/2016 - 10:15 PM

docker commands

docker commands

Creating an image

  1. Create a single Dockerfile in ~/dockerfile/Dockerfile
FROM centos
VOLUME /Users/sundar.rajagopalan/Downloads
VOLUME /Users/sundar.rajagopalan/docker-dir
RUN ["useradd", "builder"]
RUN ["yum", "install", "rpm-build", "-y"]
RUN ["yum", "install", "redhat-rpm-config", "-y"]
RUN ["yum", "install", "wget", "-y"]
RUN ["install", "-d", "-o", "builder", "-m", "755", "/home/builder/rpmbuild"]
WORKDIR "/home/builder/rpmbuild"
RUN ["install", "-d", "-o", "builder", "-m", "755", "BUILD", "RPMS", "SOURCES", "SPECS", "SRPMS"]
ENTRYPOINT ["/bin/bash"]
  1. docker build -t rpmtest .

    This creates an image called “rpmtest”

  2. Verify that the image exists by doing a:

    docker images

  3. Launch an instance with:

    docker run -i -t -v /Users/sundar.rajagopalan/Downloads:/downloads /Users/sundar.rajagopalan/build:/build --name firstone rpmtest

  4. Start a stopped instance with:

    docker start -a -i <container_id>

Commands for regular user

  1. Connecting to an existing container docker attach <container_id or container_name>

  2. Removing an image docker rmi <image_name>

Remove old docker containers:

docker rm $(docker ps -q -f status=exited)