skip to Main Content

I am a beginner in docker so I have no good knowledge but I am keen to learn more. So I hope this community can guide me.
Now I have a Dockerfile.

# getting base image debian
 FROM debian
 RUN apt-get update && apt-get install -y sudo
 RUN apt-get update && apt-get install -y vsftpd
 RUN apt-get update && apt-get install -y ftp
 RUN apt-get install nano
 RUN sudo sed -i.$(date +%F) '/^#/d;/^$/d' /etc/vsftpd.conf

# Add configuration in /etc/vsftpd.conf
 RUN echo "write_enable=YES" >> /etc/vsftpd.conf
 RUN echo "chroot_local_user=YES" >> /etc/vsftpd.conf
 RUN echo "user_sub_token=$USER" >> /etc/vsftpd.conf
 RUN echo "local_root=/home/$USER/ftp" >> /etc/vsftpd.conf
 RUN echo "userlist_enable=YES" >> /etc/vsftpd.conf
 RUN echo "pasv_min_port=40000" >> /etc/vsftpd.conf
 RUN echo "pasv_max_port=50000" >> /etc/vsftpd.conf
 RUN echo "userlist_file=/etc/vsftpd.userlist" >> /etc/vsftpd.conf
 RUN echo "userlist_deny=NO" >> /etc/vsftpd.conf

# create new group "zanui"  
RUN groupadd zanui
#user "lal" with group lal
RUN useradd -G zanui --system --create-home --no-log-init lal
RUN echo "lal:123456" | chpasswd

RUN useradd -G zanui --system --create-home --no-log-init mausam
RUN echo "mausam:123456" | chpasswd

RUN echo "lal" | sudo tee -a /etc/vsftpd.userlist
RUN echo "mausam" | sudo tee -a /etc/vsftpd.userlist

RUN mkdir /home/lal/ftp
RUN chown nobody:nogroup /home/lal/ftp
RUN chmod a-w /home/lal/ftp

RUN mkdir /home/lal/ftp/files
RUN sudo chown lal:lal /home/lal/ftp/files

RUN mkdir /home/mausam/ftp
RUN chown nobody:nogroup /home/mausam/ftp
RUN chmod a-w /home/mausam/ftp

RUN mkdir /home/mausam/ftp/files
RUN sudo chown mausam:mausam /home/mausam/ftp/files

RUN apt-get update && apt-get install -y build-essential git libfuse-dev libcurl4-openssl-dev libxml2-dev mime-support automake libtool pkg-config libssl-dev
RUN git clone https://github.com/s3fs-fuse/s3fs-fuse
WORKDIR /s3fs-fuse
RUN ./autogen.sh && ./configure --prefix=/usr --with-openssl && make && make install
WORKDIR /../
ADD /conf/passwd-s3fs /etc/passwd-s3fs
RUN chmod 600 /etc/passwd-s3fs

# RUN s3fs bucket-name /home/lal/ftp/files

First I build the image from Dockerfile using the command:

docker build -t mydebiantest1:1.0 .

Then I run the container using this image using the following command:

docker run --privileged -it mydebiantest1:1.0 bash

Then I will be inside Debian Linux bash instance

root@c875e352e4e7:/# 

So now what I want is that how can run these steps when I run the command :

docker-compose up

Somehow I have managed to build docker-compose.yml file which seems not working what I want.

version: '3'
services:
  # The Application
  s3bucketftp:
    container_name: s3bucketftp
    image: s3bucketftp:1.0
    build:
      context: ./
      dockerfile: Dockerfile
      args:
        environment: development

2

Answers


  1. If you want to set up many containers at one time you need to configure docker-compose file and that’s all. You needn’t build the container from the image manually. It docker-compose does when first time builds and runs containers.

    Create an empty folder called ‘docker’ and inside ‘docker’ directory create a directory with the name ‘s3’, put there your docker file there.
    Move there and there in terminal type:

    touch docker-compose.yml
    vim docker-compose.yml
    

    Put there this content

    version: '2'
    
    services:
      # The Application
      s3bucketftp:
        container_name: s3bucketftp
        build:
          context: ./
          dockerfile: ./s3/Dockerfile
          args:
            environment: development
    

    If you want to open a terminal in some specific container you should use the command:

    docker exec -it {containerName} /bin/bash
    

    If it won’t work, you should try to give as second argument executable terminal, so in final your command to go inside the container will be

    docker exec -it {containerName} {pathToExecutableInContainer}
    
    Login or Signup to reply.
  2. Your Dockerfile does not have either CMD or ENTRYPOINT. If launching a container to use interactively as the objective, then add

    CMD /bin/bash
    

    You need not provide both image and build context for your service. You need a pre-built tagged image either locally or in the docker repository if the image attribute is specified.

    Instead let the docker to build a new image based on the provided context.

    The updated docker-compose.yaml would look like,

    version: '3'
    services:
      s3bucketftp:
        container_name: s3bucketftp
        privileged: true
        tty: true
        build:
          context: ./
          args:
            environment: development
    

    With this compose file, you can build the image and start the container (please note that you have run the compose commands from the same location as your compose file).

    Also note that this service cannot be scaled as the container_name is specified.

    docker-compose up -d
    

    -d is to run the container as the background process

    And check for running container,

    docker-compose ps
    

    Once the container is running, the container can be accessed directly without having to redo any of the setup.

    docker exec -it s3bucketftp /bin/bash
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search