# pull image - `docker pull image_name` # Dockerfile ## ubuntu ```dockerfile FROM ubuntu:latest # Set the working directory to the user's home directory WORKDIR /home/huang # Install necessary packages RUN apt-get update && apt-get upgrade && apt-get install -y vim git g++ cmake # Add a user name huang RUN useradd huang # Set a password for the user (replace 'password' with your desired password) #RUN echo 'myuser:password' | password # add a user to sudoer USER huang # Set the entry point for your application, if needed # ENTRYPOINT ["/path/to/your/application"] # Optionally, set other environment variables or instructions as needed ``` # build your own image - go to the path where Dockerfile is - `docker build -t <user_defined_image_name> .` - ex. `docker build -t my_image .` # create container - `docker create -it --name <user_defined_container_name> image_name` - ex. `docker create -it --name my_container my_image` # start container - `docker start <user_defined_container_name` - ex. docker start my_container # Go inside container ## as a normal user - `docker exec -it <container_name> bash` ## as a root user - `docker exec -it -u 0 <container_name> bash` # Build new image based on previous container - Use case - ex. export a port from it ## commit the container - The following will create a new image based on specific container `docker commit your-container-id your-new-image-name` ## Add new arguments to it (export a port) `docker run -p host_port:container_port [-p <host-port-2>:<container-port-2>] --name new_container_name your-new-image-name`